Skip to content

Commit 0bb1780

Browse files
committed
Used Dispose pattern for disposing the app
1 parent 3509742 commit 0bb1780

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Apps/QueryLogsDuckDBApp/App.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,32 @@ public sealed class App : IDnsApplication, IDnsQueryLogger, IDnsQueryLogs
4444
private bool _disposed;
4545
private IDnsServer _dnsServer;
4646
private bool _enableLogging;
47+
private bool disposedValue;
4748

4849
#endregion variables
4950

5051
#region IDisposable
5152

52-
public void Dispose()
53+
private void Dispose(bool disposing)
5354
{
54-
if (_disposed)
55-
return;
55+
if (!disposedValue)
56+
{
57+
if (disposing)
58+
{
59+
try { _channel?.Writer.TryComplete(); } catch { }
60+
try { _consumerTask?.Wait(5000); } catch { }
61+
try { _conn?.Dispose(); } catch { }
62+
}
5663

57-
try { _channel?.Writer.TryComplete(); } catch { }
58-
try { _consumerTask?.Wait(5000); } catch { }
59-
try { _conn?.Dispose(); } catch { }
64+
disposedValue = true;
65+
}
66+
}
6067

61-
_disposed = true;
68+
public void Dispose()
69+
{
70+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
71+
Dispose(disposing: true);
72+
GC.SuppressFinalize(this);
6273
}
6374

6475
#endregion IDisposable

0 commit comments

Comments
 (0)