I discovered (albiet a little bit later than the rest of the world) Eric Gamma's Design Patterns earlier this year.
One thing that I remember that he pointed out early, was that he wasn't going to address multi-threading patterns, although he thought it would be a good idea for someone to do. Since then it's been in the back of my mind to find material on this.
I've found two particularly good articles on this topic relevant to the .NET framework so far. Both spring from DevelopMentor.
The first one is a particularly good article, in the form of a presentation, .NET Windows Forms Development and Deployment.
The other one is some sample code, made available by Mike Woodring from the DevelopMentor website.
I fell in love with the elegance and simplicity of code like this the first time I saw it:
private void OnSomeEvent(IAsyncResult ar) {
if (this.InvokeRequired) { AsyncCallback cb = new AsyncCallback(this.OnSomeEvent); this.BeginInvoke(cb, new object[] { ar } ); return; }
this.Text = "Some Event..";
}
Don't forget the golden rule of Win32 programming: “Only use a Control on the thread on which it was created”.
John.
A little too elegant. It can leak. Go here, get the helper class:
http://www.bearcanyon.com/dotnet/#FireAndForget
Then change to
private void OnSomeEvent(IAsyncResult ar) {
if (this.InvokeRequired) {
AsyncCallback cb = new AsyncCallback(this.OnSomeEvent);
AsyncHelper.FireAndForget(this, cb, new object[] { ar } );
return;
}
this.Text = "Some Event..";
}
Ah, elegant again.
John.