Re: Making threadsafe calls : C# 2005

Peter Ritchie <[email protected]> Tue, 19 Jun 2007 19:27:34 -0400
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <LISTSERV%[email protected]>
On Tue, 19 Jun 2007 14:49:38 -0400, Peter Osucha
<[email protected]> wrote:

>(Eddie, your suggestion is what I am doing though for some reason, it
>seems like 'cheating').

It's not cheating, it's paving the way for making your life (or the person
supporting customers) more difficult.

Windows itself does not support cross-thread calls on most messages.
(there was some chatter than this would change in Vista, but as far as I
know it hasn't)  In most cases what happens is the thread receiving the
message receives a pointer to memory that was sent on the other thread;
because the other thread has continued running it may have deallocated
that memory by the  time the other thread accesses.  Under heavy load the
memory may have been reused by the time the other thread does anything
with the memory--resulting in the destination thread getting completely
different data (or even worse, data it doesn't have access to).  This
manifests itself as strange and random errors that are extremely difficult
to track down.

Yes, you can use things like setting CheckForIllegalCrossThreadCalls to
false; but it's an indication of a big problem that if you put off by
ignoring it, means a much more work when you do the eventual redesign.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com