Skip to content

Commit

Permalink
simplify client cleanup to happen when stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Apr 15, 2024
1 parent 2350791 commit 56f2d52
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/ChorusHub/Advertiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void Start()

private void Work()
{
bool cancelled = false;
try
{
while (!_cancellationTokenSource.Token.IsCancellationRequested)
Expand All @@ -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)
Expand Down Expand Up @@ -123,6 +109,9 @@ public void Stop()
_cancellationTokenSource.Cancel();
_thread.Join(2 * 1000);
_thread = null;
_client.Close();
_client.Dispose();
_client = null;
}

public void Dispose()
Expand Down

0 comments on commit 56f2d52

Please sign in to comment.