Search code examples
wpfwindows-phone

Wpf Dispatcher.BeginInvoke delegate issue


In my WP SignalR application I'm using this code:

_dataHub.Subscribe("ReceiveMessage").Received += list => App.RootFrame.Dispatcher.BeginInvoke(() => Messages.Add(list[0].ToString()));

But I have to use similar code to subscribe to my SignalR server application.

I tried this one:

 _dataHub.Subscribe("ReceiveMessage").Received += list => Dispatcher.CurrentDispatcher.BeginInvoke(() => Messages.Add(list[0].ToString()));

I'm having delegate issue with that. Any help?


Solution

  • As described in error you are providing lambda expression instead of delegate. Use Action like this:

    _dataHub.Subscribe("ReceiveMessage").Received += list => 
                 Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => 
                                             Messages.Add(list[0].ToString())));