Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

await Dispatcher.BeginInvoke result?

$
0
0

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



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>