Progress Bar Delegate
August 1, 2007 by Ira
When I wrote my first commercial app I came across this code in a forum, that helped me update a progress bar in another form through one of my classes.
Create a the Custom Class thus;

In the MainForm

This is quite a common requirement when programming i.e. letting an instantiated class know the progress of another. Subsequent need of this functionality has resulted in my implementing this the correct “Windows” way:
Sometimes you need to pass more than one value or object in the delegate. As a best practice the signature of a delegate is always;
public delegate void SomeHandler(object sender, SomeEventArgs e);
This means that if you need to pass more than one value, this best practice is not adhered to. there is an elegant way to do this though. I have two classes in the illustration. The first is a custom EventArgs class that takes two values (you can modify this to take any number of values) and the second is the DoWork class where the actual works takes place. This could be the splitting of an XML file, a production line in a factory or whatever.

And Mainform will be:

Try debugging this and you should see that this is much more “sensible”, though the first example is easier to understand. This is the preferred way of declaring delegates.