简体   繁体   English

SignalR来自客户端的多个并发呼叫

[英]SignalR multiple concurrent calls from client

I would like to be able to do something like this: 我希望能够做这样的事情:

IHubProxy myHubProxy = /* ... */;

var t1 = Task.Run(() => myHubProxy.Invoke<int>("Foo");
var t2 = Task.Run(() => myHubProxy.Invoke<int>("Foo");

var r1 = await t1;
var r2 = await t2;

Where "Foo" is executed in parallel on the server. 在服务器上并行执行“ Foo”的情况。 However, the way things work by default I believe both of the calls will be synchronized to the hub's thread context and run one by one. 但是,默认情况下工作方式相信两个调用都将同步到集线器的线程上下文并一个接一个地运行。 Is there any simple way to have a single hubProxy schedule two parallel invocations on the same SignalR hubproxy/connection? 有什么简单的方法可以让单个hubProxy在同一SignalR hubproxy /连接上安排两次并行调用?

You can't send messages in parallel because a transport like webSockets uses the same connection the whole time, you would be trying to interleave messages and it can't be handled. 您不能并行发送消息,因为像webSockets这样的传输始终都使用相同的连接,因此您将尝试对消息进行交织并且无法处理。 If you need multiple transfers in parallel, then use multiple connections 如果您需要并行进行多个传输,请使用多个连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM