From d7012b068f39d5c6da74e958b7d28e28da34986f Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Sun, 25 Apr 2021 17:32:07 -0700 Subject: [PATCH] Refactor TryDisposeAll --- Desktop.Core/Services/Viewer.cs | 6 +----- Desktop.Core/Services/WebRtcSession.cs | 7 +------ Desktop.Win/Models/DirectXOutput.cs | 8 +------- Shared/Utilities/Disposer.cs | 2 +- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/Desktop.Core/Services/Viewer.cs b/Desktop.Core/Services/Viewer.cs index bed8e03c..73a1aa73 100644 --- a/Desktop.Core/Services/Viewer.cs +++ b/Desktop.Core/Services/Viewer.cs @@ -87,11 +87,7 @@ namespace Remotely.Desktop.Core.Services public void Dispose() { DisconnectRequested = true; - Disposer.TryDisposeAll(new IDisposable[] - { - RtcSession, - Capturer - }); + Disposer.TryDisposeAll(RtcSession, Capturer); GC.SuppressFinalize(this); } diff --git a/Desktop.Core/Services/WebRtcSession.cs b/Desktop.Core/Services/WebRtcSession.cs index e18ff1c9..737ec036 100644 --- a/Desktop.Core/Services/WebRtcSession.cs +++ b/Desktop.Core/Services/WebRtcSession.cs @@ -61,12 +61,7 @@ namespace Remotely.Desktop.Core.Services } catch { } PeerSession.Transceivers.RemoveAll(x => true); - Disposer.TryDisposeAll(new IDisposable[] - { - Transceiver?.LocalVideoTrack, - VideoSource, - PeerSession - }); + Disposer.TryDisposeAll(Transceiver?.LocalVideoTrack, VideoSource, PeerSession); GC.SuppressFinalize(this); } diff --git a/Desktop.Win/Models/DirectXOutput.cs b/Desktop.Win/Models/DirectXOutput.cs index 95a8bdd7..3be8ccc5 100644 --- a/Desktop.Win/Models/DirectXOutput.cs +++ b/Desktop.Win/Models/DirectXOutput.cs @@ -25,13 +25,7 @@ namespace Remotely.Desktop.Win.Models public void Dispose() { - Disposer.TryDisposeAll(new IDisposable[] - { - Adapter, - Device, - OutputDuplication, - Texture2D - }); + Disposer.TryDisposeAll(Adapter, Device, OutputDuplication, Texture2D); GC.SuppressFinalize(this); } } diff --git a/Shared/Utilities/Disposer.cs b/Shared/Utilities/Disposer.cs index 6bd29580..eee4ba58 100644 --- a/Shared/Utilities/Disposer.cs +++ b/Shared/Utilities/Disposer.cs @@ -4,7 +4,7 @@ namespace Remotely.Shared.Utilities { public static class Disposer { - public static void TryDisposeAll(IDisposable[] disposables) + public static void TryDisposeAll(params IDisposable[] disposables) { if (disposables is null) {