Dispatcher.BeginInvoke: Cannot convert lambda to System.Delegate Dispatcher.BeginInvoke: Cannot convert lambda to System.Delegate wpf wpf

Dispatcher.BeginInvoke: Cannot convert lambda to System.Delegate


Shorter:

_dispatcher.BeginInvoke((Action)(() => DoSomething()));


Since the method takes a System.Delegate, you need to give it a specific type of delegate, declared as such. This can be done via a cast or a creation of the specified delegate via new DelegateType as follows:

_dispatcher.BeginInvoke(     new Action<MyClass>((sender) => { DoSomething(); }),     new object[] { this }   );

Also, as SLaks points out, Dispatcher.BeginInvoke takes a params array, so you can just write:

_dispatcher.BeginInvoke(     new Action<MyClass>((sender) => { DoSomething(); }),     this  );

Or, if DoSomething is a method on this object itself:

_dispatcher.BeginInvoke(new Action(this.DoSomething));


Using Inline Lambda...

Dispatcher.BeginInvoke((Action)(()=>{  //Write Code Here}));