SignalR and WinRT client: Don't call Wait() on Start()

冷暖自知 提交于 2019-12-05 16:58:40
noseratio

From the comment:

There is nothing mentioned in relation to asynchronous or synchronous code. Is the code WinRT asynchronous by default or there is something else that I don't know or don't understand?

In a client-side UI app (including WinRT), there're at least two reason to not block:

  • avoid blocking the UI and keeping it fluent;
  • avoid the deadlocks as described in Stephen Cleary's blog, for cases when there's an await in the current chain of calls, on the upper stack frame;

The latter is especially important for WinRT, where asynchrony is pervasive. The whole WinRT framework has been designed to be "async all the way down", so it's very likely you'd create a deadlock if you use task.Wait or task.Result anywhere on the UI thread.

For a server-side ASP.NET app, there're also at least two reasons to not block:

  • blocking makes your web app less scalable, because the blocked thread could be serving other incoming HTTP requests.
  • the same deadlock scenario.

You may want to go through the list of links in async-await wiki for further reading materials.

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