Search code examples
wpfdispatcherbegininvoke

How to fire an event using Dispatcher.BeginInvoke in wpf


I am get confused with the following code.

someObject
.Dispatcher
.BeginInvoke(new SomeDelegate(SomeEvent), SomeParamater);

here SomeDelegate is a delegate, SomeEvent is an event of class.

When I am running the code, SomeEvent is fired and the event handler gets the control.

Can some one explain how it is running?


Solution

  • The question was: how to invoke an event defined as

    public event EventHandler<SomeEventArgs> SomeEvent;
    

    via Dispatcher.BeginInvoke?

    It is done like this:

    Dispatcher.BeginInvoke(new EventHandler<SomeEventArgs>(SomeEvent), this, new SomeEventArgs());
    

    or any other value instead of this as second argument, wich gets passed to the event handler as the sender argument.