Re: Multithreaded GUI issues
- From: "pedrito" <pixbypedrito at yahoo.com>
- Date: Mon, 20 Aug 2007 22:59:00 -0500
"Smithers" <A@xxxxx> wrote in message
news:%23tSvYZ64HHA.4880@xxxxxxxxxxxxxxxxxxxxxxx
<snip>
RE:
<< I'm not aware of things that you might do with non-GUI objects that
could still affect or otherwise interact with GUI objects>>
I ran into something last week that might be more or less relevant to this
conversation:
The FileSystemWatcher class events are raised, automatically, on separate
threads spawned by the FileSystemWatcher class, itself. So, when updating
UI components from these events, it is possible to get this exception:
"Cross-thread operation not valid: Control 'xyz' accessed from a thread
other than the thread it was created on." Two ways I have found to solve
this: (1) Make use of this.Invoke() to call the code that updates the UI
control, or (2) Set the FileSystemWatcher.SynchronizingObject property to
reference the form class. I have not run into the .SynchronizingObject
property elsewhere, but perhaps other framework classes have it or
something similar.
-S
Yeah, there was one other non-GUI thread event that I had going which was a
System.Timer.Timer.Elapsed event. That's happening in my main application
(non-gui code) which then calls into the GUI. Before doing so, it checks to
make sure that the application main form is non-null and that it has a
message loop (via a boolean I set to true in the OnLoad() and false in
OnClosing()) and then it Invokes into the GUI thread before calling stuff in
the GUI.
So that's all pretty clean.
Really, I think I've isolated all the thread stuff pretty well. I don't see
(and at this point, nProf appears to be backing it up) anywhere that non-GUI
threads can be crossing the line.
.
- References:
- Multithreaded GUI issues
- From: pedrito
- Re: Multithreaded GUI issues
- From: Peter Duniho
- Re: Multithreaded GUI issues
- From: Smithers
- Multithreaded GUI issues
- Prev by Date: Re: String
- Next by Date: Re: VBA macro not executing when called from a separate thread
- Previous by thread: Re: Multithreaded GUI issues
- Next by thread: Re: Multithreaded GUI issues
- Index(es):
Relevant Pages
|