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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -