summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2020-10-23 18:33:26 +0100
committersr55 <[email protected]>2020-10-23 18:33:26 +0100
commit5cb1f0252bbd2c789af8b8dee36eff16568ac670 (patch)
treeaadfd8b47157486764a50b8eeabbd4aa62442c1b /win/CS
parent48dccd171739141b8c7deb8f9bcfaf948964cbef (diff)
WinGui: Block the completed event from re-firing if the worker process runs into trouble. #3196
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrakeWPF/Instance/RemoteInstance.cs15
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs10
2 files changed, 22 insertions, 3 deletions
diff --git a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
index a6b7d7446..8cbdf014b 100644
--- a/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
+++ b/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
@@ -45,6 +45,7 @@ namespace HandBrakeWPF.Instance
private Process workerProcess;
private Timer encodePollTimer;
private int retryCount = 0;
+ private bool encodeCompleteFired;
public RemoteInstance(ILog logService, IUserSettingService userSettingService, IPortService portService)
{
@@ -219,15 +220,23 @@ namespace HandBrakeWPF.Instance
private async void PollEncodeProgress()
{
+ if (encodeCompleteFired)
+ {
+ this.encodePollTimer?.Stop();
+ this.encodePollTimer.Dispose();
+ return;
+ }
+
ServerResponse response = null;
try
{
if (this.retryCount > 5)
{
- this.EncodeCompleted?.Invoke(sender: this, e: new EncodeCompletedEventArgs(4));
-
+ encodeCompleteFired = true;
this.encodePollTimer?.Stop();
+ this.EncodeCompleted?.Invoke(sender: this, e: new EncodeCompletedEventArgs(-11));
+
if (this.workerProcess != null && !this.workerProcess.HasExited)
{
this.workerProcess?.Kill();
@@ -277,6 +286,8 @@ namespace HandBrakeWPF.Instance
else if (taskState != null && taskState == TaskState.WorkDone)
{
this.encodePollTimer.Stop();
+ encodeCompleteFired = true;
+
if (this.workerProcess != null && !this.workerProcess.HasExited)
{
try
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
index 1474df7e7..82504aa0e 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
@@ -47,8 +47,9 @@ namespace HandBrakeWPF.Services.Encode
private HBConfiguration currentConfiguration;
private bool isPreviewInstance;
private bool isLoggingInitialised;
+ private bool isEncodeComplete;
private int encodeCounter;
-
+
public LibEncode(IUserSettingService userSettingService, ILogInstanceManager logInstanceManager, int encodeCounter, IPortService portService) : base(userSettingService)
{
this.userSettingService = userSettingService;
@@ -223,6 +224,13 @@ namespace HandBrakeWPF.Services.Encode
{
this.IsEncoding = false;
+ if (isEncodeComplete)
+ {
+ return; // Prevent phantom events bubbling up the stack.
+ }
+
+ this.isEncodeComplete = true;
+
string completeMessage = "Job Completed!";
switch (e.Error)
{