SignalR和WinRT的客户:不要调用wait()上的开始() [英] SignalR and WinRT client: Don't call Wait() on Start()

查看:407
本文介绍了SignalR和WinRT的客户:不要调用wait()上的开始()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于SignalR的官方文档的问题 - 的集线器API指南 - .NET客户端。在部分 - 如何建立一个连接。已经写了下面的事情:

I have a question regarding SignalR's official documentation - Hubs API Guide - .NET Client. In the section - How to establish a connection. It has been written the following thing:

Start方法异步执行。为了确保后续   的code线没有连接建立之后才执行,   使用伺机在一个一个ASP.NET 4.5异步方法或.Wait()   同步方法。不要在WinRT的客户端使用.Wait()。

The Start method executes asynchronously. To make sure that subsequent lines of code don't execute until after the connection is established, use await in an ASP.NET 4.5 asynchronous method or .Wait() in a synchronous method. Don't use .Wait() in a WinRT client.

有谁知道具体是什么理由不调用wait()?此外,没有也是这个应用时,我有一个WinRT的客户,我有一个电话 hubProxy.Invoke()到服务器?

Does anyone know what is the specific reason not to call Wait()? Also, does also this apply when I have a WinRT client where I have a call with hubProxy.Invoke() to the server?

感谢您的帮助!

推荐答案

从注​​释:

有关于只字不提异步或同步   code。是code的WinRT异步默认情况下,或有东西   别的我不知道或不理解?

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?

在客户端的UI应用程序(包括WinRT的),有很至少两个理由,以不阻断:

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;

后者对于WinRT的,其中异步是很普遍的特别重要的。整个WinRT的框架已经设计为异步一路下跌,所以这是非常有可能,如果你使用,你想创建一个死锁 task.Wait task.Result 上的任何地方UI线程。

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.

有关服务器端的ASP.NET应用程序,有是还至少有两个原因不块:

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

  • 阻塞,使你的web应用程序少可扩展的,因为被阻塞的线程可以服务于其他传入的HTTP请求。​​
  • 同样的死锁情况。

您可能想通过在 异步等待维基进一步阅读材料。

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

这篇关于SignalR和WinRT的客户:不要调用wait()上的开始()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆