Re: This program is not thread safe and cause run time error in debug mode
- From: Marc Gravell <marc.gravell@xxxxxxxxx>
- Date: Sun, 3 Feb 2008 03:54:12 -0800 (PST)
So because of that I assume that the thread handling must be differentYes; there is a debug assistant that detects this; there is also a
between debug mode and release mode?
static property that can tweak this behavior (I suggest setting it to
*true*): http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.checkforillegalcrossthreadcalls.aspx
2.Is it always advisable to fix run time error of the kind that I have inYes; you have a bug
this program?
3. My third question is how do I fix the program with the same
functionallity
which mean that I can subscribe to the event and unsubscribe to the event
without causing
run time error?
I'd need to look at it in debug (no time at this second), but normally
the answer is to (in any UI handler that is going to be fired by a non-
UI thread) use InvokeRequired / BeginInvoke / Invoke to pass control
to the UI thread. You can also use the sync-context. I'll see if I can
have a look later...
Marc
.
- Follow-Ups:
- References:
- This program is not thread safe and cause run time error in debug mode
- From: Tony Johansson
- This program is not thread safe and cause run time error in debug mode
- Prev by Date: Re: Firt day and last day of week (weeknumber as parameter ans year)
- Next by Date: Re: GetElementById
- Previous by thread: This program is not thread safe and cause run time error in debug mode
- Next by thread: Re: This program is not thread safe and cause run time error in debug mode
- Index(es):
Relevant Pages
|