private void Disconnect() { var disconnect = s2smtClient.Disconnect() .ContinueWith((t) => { if (t.IsFaulted) { Trace.TraceError("Disconnect call to client failed. {0}", t.Exception); } s2smtClient.Dispose(); s2smtClient = null; }) .ContinueWith((t) => { if (t.IsFaulted) { Trace.TraceError("Disconnected but there were errors. {0}", t.Exception); } else { Trace.TraceInformation("Disconnected. cid='{0}'", correlationId); } }); disconnect.Wait(); while (disconnect.Status != TaskStatus.RanToCompletion) { Trace.TraceInformation("Thread ID: {0}, Status: {1}", Thread.CurrentThread.ManagedThreadId, disconnect.Status); } }
private void Disconnect() { if (this.currentState != UiState.Connected) { return; } UpdateUiState(UiState.Disconnecting); miniwindow.Hide(); if (recorder != null) { recorder.StopRecording(); recorder.DataAvailable -= OnRecorderDataAvailable; recorder.Dispose(); recorder = null; } if (streamAudioFromFileInterrupt != null) { streamAudioFromFileInterrupt.Cancel(); streamAudioFromFileInterrupt = null; } if (player != null) { player.Stop(); player.Dispose(); player = null; } // Close the audio file if logging if (audioSent != null) { audioSent.Flush(); audioSent.Dispose(); audioSent = null; } if (this.audioReceived != null) { this.audioReceived.Dispose(); this.audioReceived = null; } var task = s2smtClient.Disconnect() .ContinueWith((t) => { if (t.IsFaulted) { this.Log(t.Exception, "E: Disconnect call to client failed."); } s2smtClient.Dispose(); s2smtClient = null; }) .ContinueWith((t) => { if (t.IsFaulted) { this.Log(t.Exception, "E: Disconnected but there were errors."); } else { this.Log("I: Disconnected."); } this.SafeInvoke(() => { this.AutoSaveLogs(); this.UpdateUiState(UiState.ReadyToConnect); }); }); }