Follow @RoyOsherove on Twitter

UI Threading Helper Classes

Following up on my post about how UI threading sucks , and Julie's post about the subject (Julie or Julia? which is it?), I've decided to create some helper classes for working with UI threads. Meet UIThreadHandler and UIThreadManager.

Basically, they save you a lot of time by saving you the trouble of creating method stubs which call Invoke() on the form (which is what you need to do when getting events from a separate thread).

You can read all about them and how to use them - here, or you can just download the code and look.

but here's a taste: This is all I need to do to call events from a separate thread - no need to create a method stub   - just creating a new UIThreadHandler does the job:

EventThrower e = new EventThrower();

UIThreadHandler h = UIManager.CreateHandler(this,new EventHandler(this.UpdateProgressBar));

e.OnEventThrow+=new MyHandler(h.BaseEventHandler);

e.Start();

I think these classes could be expended much further, but for now they save me a bunch of time already. Have fun :)

FeedDemon

UI Threading Helper Classes