xamarin.ios - Xamarin(PCL) - Signal R - System.InvalidOperationExceptionConnection started reconnecting before invocation result was received -


i getting system.invalidoperationexceptionconnection started reconnecting before invocation result received exception signal r chat, using signal r client in pcl of xamarin project

here chat service class-

public class chatservice : ichatservice {     private ihubproxy _hubproxy;     private hubconnection _hubconnection;     private readonly imobileserviceclient _mobileclient;     private readonly iinsightsservice _insightsservice;     private readonly ichatmessagerepository _chatrepository;      public chatservice(imobileserviceclient mobileclient, iinsightsservice insightsservice, ichatmessagerepository chatrepository)     {         _insightsservice = insightsservice;         _mobileclient = mobileclient;         _chatrepository = chatrepository;     }      public event eventhandler<chatmessage> messagereceived;      public async task connect(bool dismisscurrentconnection = false)     {         try         {             if (!crossconnectivity.current.isconnected)             {                 return;             }              // create new connection avoid signalr close event delays             if (_hubconnection != null)             {                 if (!dismisscurrentconnection)                 {                     return;                 }                  _hubconnection.statechanged -= onconnectionstatechangedhandler;                 _hubconnection.reconnected -= onreconnectedhandler;                 // don´t call connection.dispose() or may block 20 seconds                 _hubconnection = null;                 _hubproxy = null;             }              _hubconnection = new hubconnection(identifiers.environment.chaturl);             // connection.transportconnecttimeout = timespan.fromseconds(5);             _hubconnection.tracewriter = new debugtextwriter("signalr");             _hubconnection.tracelevel = tracelevels.all;             _hubconnection.statechanged += onconnectionstatechangedhandler;             _hubconnection.reconnected += onreconnectedhandler;              if (_mobileclient.currentuser == null)                 throw new exception("mobileclient.currentuser null. have login azure mobile service first.");              _hubconnection.headers[httpheaders.xzumoauth] = _mobileclient.currentuser.mobileserviceauthenticationtoken;              _hubproxy = _hubconnection.createhubproxy(identifiers.chathubname);              _hubproxy.on<chatmessage>("addmessage", message =>             {                 messagereceived?.invoke(this, message);             });              if (_hubconnection.state == connectionstate.disconnected)             {                 await _hubconnection.start();             }         }         catch (exception ex)         {             _insightsservice.reportexception(ex);         }     }      private async void onconnectionstatechangedhandler(statechange change)     {         if (_mobileclient?.currentuser != null && change.newstate == connectionstate.disconnected && crossconnectivity.current.isconnected)         {             // signalr doesn´t after disconnected state, need manually reconnect             await connect(true);         }     }      private void onreconnectedhandler()     {         debug.writeline("[signalr] signalr reconnected hub: {0}", identifiers.chathubname);     }      public async task sendmessage(chatmessage message)     {         try         {                            if (_hubconnection.state == connectionstate.disconnected)             {                 await connect(true);             }              await _hubproxy.invoke("send", message);         }         catch (exception ex)         {             try             {                 await _chatrepository.insertasync(message);             }             catch (exception ex2)             {                 _insightsservice.reportexception(ex);                 _insightsservice.reportexception(ex2);                 throw ex;             }         }     }      public async task joinchatroom(string chatroomid)     {         try         {             if (_hubconnection.state == connectionstate.disconnected)             {                 await connect(true);             }              await _hubproxy.invoke("joinchatroom", chatroomid);         }         catch (exception ex)         {             _insightsservice.reportexception(ex);         }     }      public async task leavechatroom(string chatroomid)     {         try         {             if (_hubconnection.state == connectionstate.disconnected)             {                 await connect(true);             }              await _hubproxy.invoke("leavechatroom", chatroomid);         }         catch (exception ex)         {             _insightsservice.reportexception(ex);         }     }      public void disconnect()     {         try         {             if (_hubconnection != null && _hubconnection.state != connectionstate.disconnected)                 _hubconnection.stop();         }         catch (exception ex)         {             _insightsservice.reportexception(ex);         }     } } 

how can prevent , catch exception? not though


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -