C#, How to hande SSH timeout Exception with SharpSSH -


i trying connect remote server using sharp ssh. timeout exception receive network based exception. want program more robust if network has problems, or if server isn't available. time out occurs @ open command , throws io timeout exception.

i hoping solve intermittent problem end.

mysqlconnectionstring = string.format(     "server={0};user={1};database=mta;port=3306;password={2}",      sqlhost, mysqluser, mysqlpass);  se = new sshexec(host, user, pass); msc = new mysqlconnection(mysqlconnectionstring);  // connect server , list of  // firmware versions , serial numbers available se.connect();  lblconnected.text = (se.connected) ? "connected" : "not connected";  msc.open();         //exception happens here 

my question: there way can tell c# application try connect command again should encounter exception?

try using try catch block:

        mysqlconnectionstring = string.format("server={0};user={1};database=mta;port=3306;password={2}", sqlhost, mysqluser, mysqlpass);          se = new sshexec(host, user, pass);         msc = new mysqlconnection(mysqlconnectionstring);         // connect server , list of firmware versions , serial numbers available         se.connect();          lblconnected.text = (se.connected) ? "connected" : "not connected";          try         {             msc.open();  //exception happens here         }         catch (exception)         {             //do stuff, i.e. retry connection             msc.open();         } 

to sure can use nested try/catch:

        mysqlconnectionstring = string.format("server={0};user={1};database=mta;port=3306;password={2}", sqlhost, mysqluser, mysqlpass);          se = new sshexec(host, user, pass);         msc = new mysqlconnection(mysqlconnectionstring);         // connect server , list of firmware versions , serial numbers available         se.connect();          lblconnected.text = (se.connected) ? "connected" : "not connected";          try         {             msc.open();  //exception happens here         }         catch (exception)         {             //do stuff, i.e. retry connection             try             {                 msc.open();  //exception happens here             }             catch (exception)             {                 //do stuff             }         } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -