Skip to content

Commit

Permalink
Added try..catch blocks and null checks to ChatClient to ensure clean…
Browse files Browse the repository at this point in the history
… disposal
  • Loading branch information
csharpfritz committed Jan 6, 2019
1 parent ed8f4d6 commit 6bd9ac9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Fritz.Twitch/ChatClient.cs
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -60,8 +60,9 @@ internal ChatClient(ConfigurationSettings settings, ILogger logger)
~ChatClient()
{

Logger.LogError("GC the ChatClient");

try {
Logger?.LogError("GC the ChatClient");
} catch {}
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(false);
}
Expand Down Expand Up @@ -294,7 +295,9 @@ private string ReadMessage()
protected virtual void Dispose(bool disposing)
{

Logger.LogWarning("Disposing of ChatClient");
try {
Logger?.LogWarning("Disposing of ChatClient");
} catch {}

if (!disposedValue)
{
Expand All @@ -303,7 +306,7 @@ protected virtual void Dispose(bool disposing)
_Shutdown.Cancel();
}

_TcpClient.Dispose();
_TcpClient?.Dispose();
disposedValue = true;
}
}
Expand Down

0 comments on commit 6bd9ac9

Please sign in to comment.