Skip to content

Commit 02271d0

Browse files
committed
Used Dispose pattern for disposing the app
1 parent 3509742 commit 02271d0

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

Apps/QueryLogsDuckDBApp/App.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,31 @@ public sealed class App : IDnsApplication, IDnsQueryLogger, IDnsQueryLogs
4444
private bool _disposed;
4545
private IDnsServer _dnsServer;
4646
private bool _enableLogging;
47-
4847
#endregion variables
4948

5049
#region IDisposable
5150

5251
public void Dispose()
5352
{
54-
if (_disposed)
55-
return;
53+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
54+
Dispose(disposing: true);
55+
GC.SuppressFinalize(this);
56+
}
5657

57-
try { _channel?.Writer.TryComplete(); } catch { }
58-
try { _consumerTask?.Wait(5000); } catch { }
59-
try { _conn?.Dispose(); } catch { }
58+
private void Dispose(bool disposing)
59+
{
60+
if (!_disposed)
61+
{
62+
if (disposing)
63+
{
64+
try { _channel?.Writer.TryComplete(); } catch { }
65+
try { _consumerTask?.Wait(5000); } catch { }
66+
try { _conn?.Dispose(); } catch { }
67+
}
6068

61-
_disposed = true;
69+
_disposed = true;
70+
}
6271
}
63-
6472
#endregion IDisposable
6573

6674
#region private

0 commit comments

Comments
 (0)