diff --git a/src/ChorusHub/Advertiser.cs b/src/ChorusHub/Advertiser.cs index 8d360483..9e76fc78 100644 --- a/src/ChorusHub/Advertiser.cs +++ b/src/ChorusHub/Advertiser.cs @@ -42,7 +42,6 @@ public void Start() private void Work() { - bool cancelled = false; try { while (!_cancellationTokenSource.Token.IsCancellationRequested) @@ -56,23 +55,10 @@ private void Work() Task.Delay(1000).Wait(_cancellationTokenSource.Token); } } - catch (OperationCanceledException) - { - cancelled = true; - } - catch(ThreadAbortException) - { - cancelled = true; - } catch(Exception) { //EventLog.WriteEntry("Application", string.Format("Error in Advertiser: {0}", error.Message), EventLogEntryType.Error); } - - if (_cancellationTokenSource.Token.IsCancellationRequested && cancelled) - { - _client.Close(); - } } public static void SendCallback(IAsyncResult args) @@ -123,6 +109,9 @@ public void Stop() _cancellationTokenSource.Cancel(); _thread.Join(2 * 1000); _thread = null; + _client.Close(); + _client.Dispose(); + _client = null; } public void Dispose()