I noticed in .NET 4.5 that the WPF Dispatcher had gotten a new set of methods to execute stuff on the Dispatcher’s thread called InvokeAsync. Before, .NET 4.5 we had Invoke and BeginInvoke which handled this syncronously and asynchronously respectively.
Besides the naming and the slightly different overloads available, are there any major differences between the BeginInvoke and the InvokeAsync methods?
Oh, and I already checked, both can be awaited:
private async Task RunStuffOnUiThread(Action action)
{
// both of these works fine
await dispatcher.BeginInvoke(action);
await dispatcher.InvokeAsync(action);
}
There are no differences as the
BeginInvokemethod calls a privateLegacyBeginInvokeImplmethod which itslef calls the private methodInvokeAsyncImpl(the method used byInvokeAsync). So it’s basically the same thing. It seems like it’s a simple refactoring, however it’s strange theBeginInvokemethods weren’t flagged as obsolete.BeginInvoke :
InvokeAsync :