From 2d56af757adabf21c58d4b10d6339c2d58e7ec5e Mon Sep 17 00:00:00 2001 From: Giang Nguyen Date: Tue, 12 Dec 2023 20:26:17 +0200 Subject: [PATCH] refactor: Extracted `TryCleanUpDteProvider` method Added null check in case the cleanup is done simultaneously in different processes --- .../AutomationInterface.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/TwinGet.AutomationInterface/AutomationInterface.cs b/src/TwinGet.AutomationInterface/AutomationInterface.cs index 73fa944..ff06b1d 100644 --- a/src/TwinGet.AutomationInterface/AutomationInterface.cs +++ b/src/TwinGet.AutomationInterface/AutomationInterface.cs @@ -29,17 +29,24 @@ public AutomationInterface() _dteProvider = new(this, true); } + protected void TryCleanUpDteProvider() + { + if (_dteProvider is null) { return; } + + /// We only dispose the that we created. + if (_dteProvider.Owner == this) + { + _dteProvider.Dispose(); + } + } + protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { } - /// We only dispose the that we created. - if (_dteProvider.Owner == this) - { - _dteProvider.Dispose(); - } + TryCleanUpDteProvider(); _disposedValue = true; } }