Skip to content

Commit 6bd9ac9

Browse files
committed
Added try..catch blocks and null checks to ChatClient to ensure clean disposal
1 parent ed8f4d6 commit 6bd9ac9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Fritz.Twitch/ChatClient.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.Extensions.Logging;
2-
using Microsoft.Extensions.Options;
32
using System;
3+
using Microsoft.Extensions.Options;
44
using System.Collections.Generic;
55
using System.Diagnostics;
66
using System.IO;
@@ -60,8 +60,9 @@ internal ChatClient(ConfigurationSettings settings, ILogger logger)
6060
~ChatClient()
6161
{
6262

63-
Logger.LogError("GC the ChatClient");
64-
63+
try {
64+
Logger?.LogError("GC the ChatClient");
65+
} catch {}
6566
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
6667
Dispose(false);
6768
}
@@ -294,7 +295,9 @@ private string ReadMessage()
294295
protected virtual void Dispose(bool disposing)
295296
{
296297

297-
Logger.LogWarning("Disposing of ChatClient");
298+
try {
299+
Logger?.LogWarning("Disposing of ChatClient");
300+
} catch {}
298301

299302
if (!disposedValue)
300303
{
@@ -303,7 +306,7 @@ protected virtual void Dispose(bool disposing)
303306
_Shutdown.Cancel();
304307
}
305308

306-
_TcpClient.Dispose();
309+
_TcpClient?.Dispose();
307310
disposedValue = true;
308311
}
309312
}

0 commit comments

Comments
 (0)