multithreading - C# SignalR Client -
i'm using signalr client version 2.2.0 nuget.
this._connection = new hubconnection(this._url); this._connection.closed += this.connectiononclosed; this._connection.error += this.connectiononerror; servicepointmanager.defaultconnectionlimit = 250; this._client = this._connection.createhubproxy(hubname); this._connection.start(new websockettransport()).wait(); then reuse client every time (multi-threaded):
client.invoke<bool>(nameof(this.addifnotexists), key, data, expireafter)
parallel.for(             0,             50000,             new paralleloptions             {                 maxdegreeofparallelism = 10,             },             async (i) =>             {                 var result = await client.executedistributedasync(                     (i % 2).tostring(),                     timespan.fromseconds(5),                     async () =>                         {                             await task.delay(500);                             return $"done: {i} [{(i % 2)}]";                         });                 console.writeline("--->" + (result ?? "timeout:" + i));             }); this crashes (1st addifnotexist works , next 8 crashes). i've read everywhere ihubproxy supposed thread-safe... suggestions?
solution create objectpool , threads take pool , put when done using. signalr client not threadsafe sure.
Comments
Post a Comment