The first defines the delegate, the second defines the event. The two are related to each other, but they are usually used very differently.
In general, if you use EventHandler or EventHandler<T> , this assumes that you are using an event. The caller (to process progress) usually subscribes to the event (does not pass in the delegate), and you can raise this event if you have subscribers.
If you want to use a more functional approach and pass the delegate, I would choose a more suitable delegate to use. In this case, you really do not provide any information in EventArgs , so perhaps using System.Action would be more appropriate.
Thus, an event-based approach seems to be more appropriate here, from a little code. For more information on using events, see Events in the C # Programming Guide.
Your code, using events, most likely will look something like this:
When you call your progress, you should write:
var handler = this.ProgressChanged; if (handler != null) handler(this, EventArgs.Empty);
A user of this type would write this as:
yourClass.ProgressChanged += myHandler; yourClass.Download(url);
source share