Re: This program is not thread safe and cause run time error in debug mode

Tech-Archive recommends: Fix windows errors by optimizing your registry



So because of that I assume that the thread handling must be different
between debug mode and release mode?
Yes; there is a debug assistant that detects this; there is also a
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 in
this program?
Yes; you have a bug

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
.



Relevant Pages

  • Re: This program is not thread safe and cause run time error in debug mode
    ... between debug mode and release mode? ... static property that can tweak this behavior (I suggest setting it to ... run time error? ... UI thread) use InvokeRequired / BeginInvoke / Invoke to pass control ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System.Threading.Timer improper function in Release mode
    ... > I have an engine that uses a System.Threading.Timer to invoke a delegate ... > Everything works just fine when the code is build in Debug mode, ... > the code is build in Release mode the delegate is invoked once only. ... > The workaround solution I used was declaring the timer as static. ...
    (microsoft.public.dotnet.languages.csharp)
  • _CrtIsValidHeapPointer
    ... I have run time error in ... _CrtIsValidHeapPointer(const void * pUserData=0x01482868) ... My Project settings conform to:- ...
    (microsoft.public.vc.language)
  • RE: OLE action error thru automation
    ... I would suspect that Access or Excel is encountering a run time error or you are in debug mode in one or both environments. ...
    (microsoft.public.excel.programming)
  • Re: xl2007 problem, points(i).datalabel.top gives overflow
    ... When changing the .Top property I get an "overflow" run time error, ... but then in debug mode I can step through the offending statement and ... I found a workaround by selecting the chart point, ...
    (microsoft.public.excel.programming)