I have something I must do in the UI thread. Therefore I do that :
Dispatcher.Invoke(() =>{ what I must do in the UI thread}
When I put this line inside a function, it works but it doesn't work inside a delegate like in this example:
public Action f = () => // it does'nt work
{
Dispatcher.Invoke(() => {what I must do in the UI thread });
}
public void ff() // it works
{
Dispatcher.Invoke(() => { what I must do in the UI thread });
}
The error is the following :
a field initializer can not reference the non-static-field, method or property DispatcherObjet.Dispatcher