Re: Threading changes in .NET 2
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Wed, 22 Mar 2006 17:04:05 +0100
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)?
|
.
- Follow-Ups:
- Re: Threading changes in .NET 2
- From: William Stacey [MVP]
- Re: Threading changes in .NET 2
- From: Brian Gideon
- Re: Threading changes in .NET 2
- References:
- Threading changes in .NET 2
- From: Chris S.
- Re: Threading changes in .NET 2
- From: jeremiah johnson
- Re: Threading changes in .NET 2
- From: Kevin Spencer
- Re: Threading changes in .NET 2
- From: Chris S.
- Re: Threading changes in .NET 2
- From: Brian Gideon
- Threading changes in .NET 2
- Prev by Date: Re: JON SKEET! i need your help!
- Next by Date: Re: Passing Data From Cust Control To main Form [C# Win]
- Previous by thread: Re: Threading changes in .NET 2
- Next by thread: Re: Threading changes in .NET 2
- Index(es):
Relevant Pages
|