Hi,
I am looking for the supposed way of getting result from the Dispatcher.BeginInvoke using the async/await pattern. I have noted that the DispatcherOperation that the method returns is awaitable, however, it is of type void.
I do not want to make callbacks from the delegate being dispatched, since I want the result back on the calling thread.
It also seems to me that checking the DispatcherOperation.Status and subscribing DispatcherOperation.Completed has concurrency issues and requires not exactly elegant code when we have the async/await pattern.
The simplest thing I was able to come up with is:
DispatcherOperation operation = MyDispatcher.BeginInvoke(func, params); await operation; return operation.Result;
Is this really it? What is the reason the operation uses Task and not Task<object> resp. DispatcherOperation<object>?
Thanks,
Jan