private void DisableConnection() { // Disable the forward channel myXmlRpcProxy = null; // Disable the back channel // NOTE: this should not be necessary in normal operation, but could consider // a future change to indicate the connection to the instrument has been lost! // For example, throw an application exception/fire an event so the UI can // indicate that server connectivity has been lost. }
private InstrumentControlProxy() { // Create the objects that represent the control/event connections... // Make initial attempt to connect to the Instrument Control server. // Get the number of times to re-try if the connection attempt fails. NameValueCollection nvc = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("Separator/InstrumentControlConnection"); int retryCount, retryWait; try { retryCount = int.Parse(nvc.Get("RetryCount")); retryWait = int.Parse(nvc.Get("RetryWait_ms")); } catch { // Set default values in case the parse fails retryCount = 3; retryWait = 2000; // milliseconds } do { try { myXmlRpcProxy = new InstrumentControlXmlRpcProxy( RemotingInfo.GetInstance().IcsServerURL); retryCount = 0; // Clear the retry count as we're now connected. } catch (Exception ex) { // Connection attempt failed. Re-try if the number of attempts so far is // within the retry count specified in the application configuration file, // otherwise propagate an exception to tell the caller we failed to connect. myXmlRpcProxy = null; LogFile.AddMessage(TraceLevel.Warning, "retryCount = " + retryCount + " " + ex.Message); if (--retryCount <= 0) { throw new ApplicationException( SeparatorResourceManager.GetSeparatorString( StringId.ExFailedToConnectToInstrumentControl)); } // Pause before retrying connection attempt Thread.Sleep(retryWait); } } while (retryCount > 0); }