void SaveState() { #if DEBUG WriteLog("Start Saving State"); #endif StreamWriter sw = null; try { var state = new VirtualRouterServiceState(); state.IsStarted = this.virtualRouterHost.IsStarted(); var conn = this.virtualRouterHost.GetSharedConnection(); if (conn != null) { if (conn.Guid != null) { state.SharedConnectionGuid = this.virtualRouterHost.GetSharedConnection().Guid.ToString(); } } var connSettings = this.virtualRouterHost.GetConnectionSettings(); state.SSID = connSettings.SSID; state.MaxPeerCount = connSettings.MaxPeerCount; state.Password = this.virtualRouterHost.GetPassword(); sw = new StreamWriter(new FileStream(strStateFileName, FileMode.Create)); var stream = sw.BaseStream; var serializer = new DataContractSerializer(typeof(VirtualRouterServiceState)); serializer.WriteObject(stream, state); } catch (Exception ex) { WriteLog("Error Saving Service State - " + ex.ToString()); } finally { if (sw != null) { sw.Close(); sw.Dispose(); } } #if DEBUG WriteLog("State Saved"); #endif }