how to forget synchronization context in async methods in c#

我的梦境 提交于 2019-12-04 10:08:21

I'd like to make the method as easy to use as possible. That means that anyone should be able to call it synchronously by accessing the Result member of the returned Task.

There is no easy way to create a synchronous wrapper for an asynchronous method. It's best to let asynchronous methods be asynchronous.

You can use ConfigureAwait(continueOnCapturedContext: false) to discard the context, but it won't be any better than Task.Run in your case since you can't change the methods that M calls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!