简体   繁体   中英

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. 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?

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. If you need multiple transfers in parallel, then use multiple connections

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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