Re: Threading changes in .NET 2

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Note that this is only true when running in debug mode, there is no such
check done when running a release build, so you won't get the exception. The
check is done by the CLR (where it's called a Managed Debugging Assistant or
MDA) and is quite expensive as it has to compare the thread ID of the thread
that accesses a window handle to the thread ID of the creator (the UI
thread) of the handle, that's why it's only done when debugging or when you
explicitly enable the MDA. Search the docs for MDA if you want to enable
this (or other MDA's) for release builds as well.


Willy.


"Brian Gideon" <briangideon@xxxxxxxxx> wrote in message
news:1143038791.661920.97470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Chris,
|
| In addition to forms and controls not being thread-safe they also have
| thread affinity requirements. They must only be accessed on the thread
| that created them. Typically, that's the main UI thread. In .NET 1.0
| and 1.1 you could access the control from another thread and it would
| appear to work fine at least some of the time. However, the behavior
| was unpredictable. I frequently observed the problems manifesting
| themselves when a control would unexpectedly appear as a large red X
| with a white background. In .NET 2.0 Microsoft decided to throw an
| exception if a control was accessed from another thread immediately
| informing the developer of a bug. That may be the exception you're
| thinking of, but it isn't thrown by Control.Invoke.
|
| Brian
|
| Chris S. wrote:
| > I've read on this thread:
| >
| >
http://groups.google.co.uk/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/1a5ae8fc268f928a/6952b054bb9ac568?lnk=st&q=Thread++.NET+2&rnum=3#6952b054bb9ac568
| >
| > about .NET 2.0 throwing exceptions with Control.Invoke. This is
| > probably the threading changes I was told about. But doesn't .NET 1.1
| > do this already when the thread doing the UI update hasn't got a handle
| > (and no InvokeRequired is used)?
|


.



Relevant Pages

  • Re: Threading changes in .NET 2
    ... check done when running a release build, so you won't get the exception. ... MDA) and is quite expensive as it has to compare the thread ID of the thread ... | and 1.1 you could access the control from another thread and it would ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading changes in .NET 2
    ... seem inside an enqueue method for the window message queue would be a good ... | and 1.1 you could access the control from another thread and it would ... That may be the exception you're ... | Chris S. wrote: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threading changes in .NET 2
    ... | check done when running a release build, so you won't get the exception. ... | explicitly enable the MDA. ... || and 1.1 you could access the control from another thread and it would ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Multithreaded GUI issues
    ... The code is happening in a try/catch handler, but the exception is taking place in a callback thread that I have no control over. ... were actually trying to close a socket at the time the exception occurred, so you might want to check to see why something is trying to close a socket when you don't expect to. ... But how do I know that creating an Image object is thread safe? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What does it mean?
    ... > But, if you would like to save yourself all of the exception processing, a ... (That's what a cast does internally.) ... > control array is a particular control. ... >> where the result isn't a TextBox, ...
    (microsoft.public.dotnet.languages.csharp)