From: sr55 Date: Sun, 3 Feb 2019 22:15:53 +0000 (+0000) Subject: WinGui: Fix instance handling in Libencode. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=948a6712a11a7fe1f1f314ebb26f728a00ba963c;p=handbrake WinGui: Fix instance handling in Libencode. --- diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs index ca4100b62..3b9e01280 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs @@ -78,6 +78,23 @@ namespace HandBrakeWPF.Services.Encode // Create a new HandBrake instance // Setup the HandBrake Instance this.log.Reset(); // Reset so we have a clean log for the start of the encode. + + if (this.instance != null) + { + // Cleanup + try + { + this.instance.EncodeCompleted -= this.InstanceEncodeCompleted; + this.instance.EncodeProgress -= this.InstanceEncodeProgress; + this.instance.Dispose(); + this.instance = null; + } + catch (Exception exc) + { + this.ServiceLogMessage("Failed to cleanup previous instance: " + exc); + } + } + this.ServiceLogMessage("Starting Encode ..."); this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity, configuration) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity, configuration); @@ -143,10 +160,6 @@ namespace HandBrakeWPF.Services.Encode if (this.instance != null) { this.instance.StopEncode(); - this.instance.EncodeCompleted -= this.InstanceEncodeCompleted; - this.instance.EncodeProgress -= this.InstanceEncodeProgress; - this.instance.Dispose(); - this.instance = null; this.ServiceLogMessage("Encode Stopped"); } } @@ -218,19 +231,6 @@ namespace HandBrakeWPF.Services.Encode e.Error ? new EventArgs.EncodeCompletedEventArgs(false, null, string.Empty, this.currentTask.Destination, hbLog, filesize) : new EventArgs.EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Destination, hbLog, filesize)); - - // Cleanup - try - { - this.instance.EncodeCompleted -= this.InstanceEncodeCompleted; - this.instance.EncodeProgress -= this.InstanceEncodeProgress; - this.instance.Dispose(); - this.instance = null; - } - catch (Exception exc) - { - this.ServiceLogMessage("Failed to cleanup Encode instance: " + exc ); - } } private long GetFilesize(string destination)