public void BeginConnect() { if (_synchronizer != null) { lock (_syncObject) { if (ConnectionState != StorageLinkConnectionState.Disconnected) { return; } _connectionState = StorageLinkConnectionState.Connecting; } OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState)); ThreadPool.QueueUserWorkItem(RunCacheLoop); } }
public ConnectionStateChangedEventArgs(StorageLinkConnectionState state) { ConnectionState = state; }
private void RunCacheLoop(object state) { try { if (_service == null) { try { _service = new StorageLinkSSLWebService(Username, Password, Host); } catch( UriFormatException e ) { savedException = e; ConnectionState = StorageLinkConnectionState.Disconnected; EndConnect(); } } while (!IsConnectionEnding) { if (ConnectionState != StorageLinkConnectionState.Connected || RefreshInProgress) { // not connected: try and update entire cache try { Update(); Error = string.Empty; ConnectionState = StorageLinkConnectionState.Connected; } catch (SoapException e) { Error = ConvertSoapException(e).Message; ConnectionState = StorageLinkConnectionState.Disconnected; } catch (WebException e) { Error = e.Message; ConnectionState = StorageLinkConnectionState.Disconnected; } RefreshInProgress = false; } if (ConnectionState == StorageLinkConnectionState.Connected) { try { _listener.ProcessEvents(); } catch (SoapException e) { Error = ConvertSoapException(e).Message; ConnectionState = StorageLinkConnectionState.Disconnected; } catch (WebException e) { Error = e.Message; ConnectionState = StorageLinkConnectionState.Disconnected; } } Thread.Sleep(ConnectionState == StorageLinkConnectionState.Connected ? 2000 : 5000); } } finally { if (_service != null) { _service.Dispose(); _service = null; } lock (_syncObject) { _ending = false; _connectionState = StorageLinkConnectionState.Disconnected; } OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState)); } }
private void RunCacheLoop(object state) { try { if (_service == null) { try { _service = new StorageLinkSSLWebService(Username, Password, Host); } catch (UriFormatException e) { savedException = e; ConnectionState = StorageLinkConnectionState.Disconnected; EndConnect(); } } while (!IsConnectionEnding) { if (ConnectionState != StorageLinkConnectionState.Connected || RefreshInProgress) { // not connected: try and update entire cache try { Update(); Error = string.Empty; ConnectionState = StorageLinkConnectionState.Connected; } catch (SoapException e) { Error = ConvertSoapException(e).Message; ConnectionState = StorageLinkConnectionState.Disconnected; } catch (WebException e) { Error = e.Message; ConnectionState = StorageLinkConnectionState.Disconnected; } RefreshInProgress = false; } if (ConnectionState == StorageLinkConnectionState.Connected) { try { _listener.ProcessEvents(); } catch (SoapException e) { Error = ConvertSoapException(e).Message; ConnectionState = StorageLinkConnectionState.Disconnected; } catch (WebException e) { Error = e.Message; ConnectionState = StorageLinkConnectionState.Disconnected; } } Thread.Sleep(ConnectionState == StorageLinkConnectionState.Connected ? 2000 : 5000); } } finally { if (_service != null) { _service.Dispose(); _service = null; } lock (_syncObject) { _ending = false; _connectionState = StorageLinkConnectionState.Disconnected; } OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState)); } }