c# - SignalR issue with invoking server method from onreceived method -


i have following signalr code desktop client:

    _hub.on<string>("ping",(string s) =>             {                 console.writeline(s + " mainhub ");                  _hub.invoke("acknowledge","say hello mainhub");              }); 

i have ping , acknowledge method on hub.

_hub.invoke("acknowledge","say hello mainhub"); 

is not firing desktop client. how write code properly?

as per link

currently in .net client serialize invoking user callbacks upon receiving messages server using taskqueue. includes callbacks registered using hubproxy.on or continuations after hubproxy.invoke. if these callbacks block, blocking waiting on result callback, receive dispatch queue stop (deadlock). should detect condition , trace error when occurs (connection.onerror). in taskqueue (with optional flag enables of course) makes monitor itself, using async loop started on first enqueue checks if task running same running on last interval. if so, log error.

now have managed fix issue quick dirty solution. know not way fix issue, dont have choices other this. other solution better higly appreciated.

 threading.timer tmr= new threading.timer(new timercallback(acknowledge),null, 0, timeout.infinite);   private void acknowldege(object state)   {    if(signalrisready)//check if signalr ready      {        _hub.invoke("acknowledge","say hello mainhub");         tmr.change(timeout.infinite, timeout.infinite);//wait until next event occurs      }   }   _hub.on<string>("ping",(string s) =>         {             console.writeline(s + " mainhub ");              tmr.change(50, timeout.infinite);// call callback after 50ms          }); 

another solution have managed using configureawait. following solution:

   _hub.on<string>("ping",async(string s) =>         {             console.writeline(s + " mainhub ");            await task.run(async()=>{               _hub.invoke("acknowledge","say hello mainhub");            }).configureawait(false);//this run task seperate thread, unblocking parent thread          }); 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -