SendOrPostCallback Represents a method to be called when a message is to be dispatched to a synchronization context. In first case SendOrPostCallback points on async method that i guess should be executed synchronously. What will happen if Delegate will point on async delegate? How behaviour should change?
Before changes:
public class ViewModel
{
public ViewModel()
{
SynchronizationContext.Current.Post(new SendOrPostCallback(SomeMethods), null);
}
private async void SomeMethods(object obj)
{
await Foo(obj);
}
private async Task Foo(object obj)
{
bool Canceled = false;
while (!Canceled)
{
await Task.Delay(3000);
//...
}
}
}
After changes:
public class ViewModelImproved
{
public ViewModelImproved()
{
SynchronizationContext.Current.Post(new SendOrPostCallback(async (obj) => { await SomeMethods(obj); }), null);
}
private async Task SomeMethods(object obj)
{
await Foo(obj);
}
private async Task Foo(object obj)
{
bool Canceled = false;
while (!Canceled)
{
await Task.Delay(3000);
}
//...
}
}