Skip to content

Commit

Permalink
refactor: Extracted TryCleanUpDteProvider method
Browse files Browse the repository at this point in the history
Added null check in case the cleanup is done simultaneously in different processes
  • Loading branch information
ahuca committed Dec 12, 2023
1 parent 5c5b46e commit 2d56af7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/TwinGet.AutomationInterface/AutomationInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@ public AutomationInterface()
_dteProvider = new(this, true);
}

protected void TryCleanUpDteProvider()
{
if (_dteProvider is null) { return; }

/// We only dispose the <see cref="_dteProvider"/> that we created.
if (_dteProvider.Owner == this)
{
_dteProvider.Dispose();
}
}

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing) { }

/// We only dispose the <see cref="_dteProvider"/> that we created.
if (_dteProvider.Owner == this)
{
_dteProvider.Dispose();
}
TryCleanUpDteProvider();
_disposedValue = true;
}
}
Expand Down

0 comments on commit 2d56af7

Please sign in to comment.