Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR multiple concurrent calls from client

Tags:

c#

signalr

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?

like image 651
ronag Avatar asked Feb 16 '23 08:02

ronag


1 Answers

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

like image 134
Gustavo Armenta Avatar answered Feb 27 '23 05:02

Gustavo Armenta