Re: Making threadsafe calls : C# 2005
Peter Osucha <[email protected]> Tue, 19 Jun 2007 21:20:48 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <019101c7b2d9$3c3349b0$0302a8c0@peterhome> |
Thank you, Peter. So it seems that what I should be doing when my 'other thread' object raises an event that is handled by one of my forms is to kick off a new thread and have that thread update the necessary form controls. Is this right? Peter -----Original Message----- From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Peter Ritchie Sent: Tuesday, June 19, 2007 7:28 PM To: [email protected] Subject: Re: [DOTNET-CX] Making threadsafe calls : C# 2005 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