Hello,
I've posted a few questions here in the past about using events which
are fired to a background task. I've taken what I learned, here and
through experimenting and tracking down bugs, and summarized it on my
Web site. I'm hoping this will be useful for others here who may be
dealing with similar issues, and also to get feedback, which I will
use to update the page and also to improve my own code.
The page is here:
http://www.suspectclass.com/~sgifford/tips/dotnet/DotNetAsyncEventTips.htm
Here is the introduction from the Web page. Please contact me if you
have any feedback, find any mistakes, etc. You can email me directly,
or if it's relevant to the group just post here. Thanks!
---Scott.
Tips on using .NET asynchronous events from a background thread
Our .NET client quite a few asynchronous events called from background
threads. We use a LargeIntervalTimer to drive events and we have a
network client which receives updates asynchronously over the network,
similar to Pocket Outlook's Always Up To Date. Besides those, if we do
something that may block for awhile, we send it off to a background
thread and have it fire events to notify us of its progress.
After working on this for awhile, we have learned (often the hard way)
that there are a few tricky things with firing events from a
background thread. The first is that they aren't running in the GUI
thread, so you will have to use Invoke/BeginInvoke to interact with
the GUI. A trickier problem is that they can fire at inconvenient
times, such as after a component has been disposed, or while it is
disposing. This page has some tips on dealing with all of the issues
we have encountered so far.