|
From MSDN: When a thread other than the creating thread of a control tries to access one of that control's methods or properties, it often leads to unpredictable results. A common invalid thread activity is a call on the wrong thread that accesses the control's Handle property. Set CheckForIllegalCrossThreadCalls to true to find and diagnose this thread activity more easily.
I surely hope you don't intend to use that in production! I'm also not sure what you mean by "manage my own threads" in VS 2003. I would still get exceptions thrown indicating I was on the wrong thread even in .Net 1.1.
Logifusion[^]
|
|
|
|
|
I only have two threads in the entire application. It is very easy to keep track of what is being accessed by each thread when the number is so small. Thats all I meant. I knew this would pinch a nerve, but my 2003 application has run perfectly since I wrote it. It really is not an issue. This feature was not nearly as strict in 2003 because I ran this exact code and never received a single error.
|
|
|
|
|
Thanks for all of your help. I really appreciate it. I have another major issue however. Could you view my post on listviews. You should see it in the newer posts.
|
|
|
|
|
Did you get this one straightened out?
|
|
|
|
|
well, i reverted to a previous method. I was completely and utterly confused by this conversation.
|
|
|
|
|
This won't work because this.Invoke(Search_ProcessingComplete) is not a valid Invoke statement. That is the wrong parameter for an invoke statement.
|
|
|
|
|
FYI, you can utilize the System.Windows.Forms.WindowsFormsSynchronizationContext object to raise events on the UI thread from your class without having to "entangle" to two objects. You don't even have to entangle your object with Windows forms either; just have it accept any old SynchronizationContext. For Windows Forms apps, you can pass in a WindowsFormsSynchronizationContext and the class then doesn't have to be specific to Windows Forms.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Looks pretty cool. My one complaint being that you're stuck with the SendOrPostCallback delegate which only takes one object. I'm not really sure you can call it raising an event either because it doesn't technically raise any events. But this is definitely a nice new tool that I'll want to experiment with in the future.
Logifusion[^]
|
|
|
|
|
It really addresses a particular problem that encompasses events: SynchronizationContext are meant for doing things (such as calling methods, raising events, etc.) on a particular thread by either Posting (which corresponds to BeginInvoke for Windows Forms) or Sending (which corresponds to Invoke for Windows Forms).
Thus, you *could* make a library that can dispatch events on a UI thread without tying your library to that control, or even to Windows Forms, for that matter. For example:
class MyCrazyLib
{
private SynchronizationContext syncContext;
public event EventHandler WorkProgressed;
public MyCrazyLib(SynchronizationContext eventRaisingSync)
{
this.syncContext = eventRaisingSync;
}
void DoWorkInBackground()
{
ThreadPool.QueueUserWorkItem(MyWorkMethod);
}
void MyWorkMethod(object state)
{
...
this.syncContext.Post(delegate(object state)
{
this.WorkProgressed(someSender, EventArgs.Empty);
});
}
}
There you've got yourself a library that *can* raise events on any thread, UI thread or otherwise. To use this with Windows Forms, you can simply do:
MyCrazyLib lib = new MyCrazyLib(WindowsFormsSynchronizationContext.Current);
lib.WorkProgressed += MyHandler;
lib.DoWorkInBackground();
...
void MyHandler(object sender, EventArgs e)
{
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Excellent! The name SynchronizationContext gave me pause because it makes me wonder if it's actually going to still let me do my work asynchronously. I can see from your example that it works just fine. Thanks for showing me this!
Logifusion[^]
|
|
|
|
|
SearchComplete is an event, not a delegate. If you want to fire the event, get rid of Parent.Invoke and use if (SearchComplete != null) SearchComplete(this, new EventArgs()); Or whatever you have to pass into your ProcessingCompleteDelegate .
Logifusion[^]
|
|
|
|
|
Whoops. I didn't even see that. Try his suggestion first. You want to raise the event on your class, not on the form. In the handler for the event (on the form), check for InvokeRequired. If it is required, then you'll have to do call this.Invoke to get it back onto your UI thread.
|
|
|
|
|
I used the wrong wording before. You are correct about it being an event, but it doesn't work either way. I have to use invoke because i will be accessing the controls of another form in another thread when i make this call. I need the event to not have the value null because i need to fire it. For whatever reason when I register ArtifactSearch for its events before I start the thread, they are not staying registered.
|
|
|
|
|
You're thinking about this backwards. The event should not care anything about what's listening to it. It doesn't care what thread the listener is in. The event should just fire. It is the job of the listener to get itself back into the main thread. You have a listener in MainForm, but when you interact with anything in MainForm, you're going to have to do it through the use of Invoke. This means you'll have to write delegates for MainForm, but luckily anonymous methods will make this easier.
Logifusion[^]
|
|
|
|
|
I don't understand what the other guy was saying about lock statements... never used them. Is this the solution?
|
|
|
|
|
In this case, I think you can get away without having to use them. Check out my comments above for more info.
|
|
|
|
|
Once you have the delegate vs event thing straightened out, here are some articles on accessing Forms from non-UI threads.
http://www.csharphelp.com/archives2/archive375.html
http://msdn2.microsoft.com/en-us/library/ms171728(VS.80,d=ide).aspx
http://weblogs.asp.net/justin_rogers/articles/126345.aspx
|
|
|
|
|
Hello all,
I've been looking into what is required to write a custom tool for Visual Studio 2005. Specifically, what I want to do is write a tool that can take an XML file containing a connection string and generate a strongly-typed wrapper around the database. Basically, the idea here is to make it so that I have easy intellisense access to the names of tables, views, fields, stored procedures, parameters, etc. so that I will stop misspelling them and to reduce the problems caused by changing the database schema. That and I want to play with the CodeDOM in a useful fashion.
So, my question is: Has anyone here implemented a custom tool and had it work in Visual Studio 2005? I know I could use a custom build provider, but I intend to be using this in business layer code. My understanding is that build providers don't work in anything other than ASP.NET.
|
|
|
|
|
Err....
I meant to say non-web code. It will actually be the data access layer, not the business layer.
|
|
|
|
|
hello Everyone,
i wrote an application with MDI Forms and have a problem which didn't know it's reason ,
which is delaying time when navigating between forms and thats all .
thanx
-- modified at 12:58 Tuesday 13th June, 2006
|
|
|
|
|
.NET 2.0
I am using the Tooltip control to notify user's of input error. The tooltip is set as a bubble tip. When a call the the Show method, the tooptip bubble does not display correctly. The buble pointer will be offset from the control.
Now if I call the show method twice in a row with the same control passed then it will display correcty.
What is causing the tooltip to not be displayed correctly when in bubble form?
|
|
|
|
|
Hi, can anyone tell me what's the difference between console.write and trace.write ?
I'm currently facing problem to trace the output of the Class file. Other than try catch, any other way to easily see the whole process log ?
Help, I'm not able to trace the class output... Am using visual webdev2005, thnks.
|
|
|
|
|
By default the Listeners collection associated with the Trace class contains only one TraceListener. That listener writes to the standard output stream (the same stream that Console writes to). You can add in different TraceListener objects to the Listeners property, which will allow your trace messages to be redirected to whatever backing stores you desire.
Josh
|
|
|
|
|
Trace class is part of the System.Diagnostics namespace which provides classes that allow you to interact with system processes, event logs, and performance counters
Trace.WriteLine: writes information about the trace to the trace listeners in the Listeners collection.
Console: represents the standard input, output, and error streams for console applications
Console.WriteLIne: Writes the specified data, followed by the current line terminator, to the standard output stream
Source: Microsoft Visual Studio Documentation
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
|
|
|
|
|
Hello,
I have 2 forms. once i make my choice of the application i wanna run Form1 is hidden and form2 is showing up. if i want to terminate my program in Form2, Form is still running. I don't wanna instantiate Form1 again in Form2 to close Form1. it's gonna create a new Form1 right?
what is the best way to terminate both forms from Form2?
Thank you
Donkaiser
|
|
|
|