Skip to content

Commit da07fee

Browse files
FarisR99FarisR99
authored andcommitted
Improve MLC run state resetting
Fixes #9 Previously if an error occurred when trying to force kill mlc.exe, the stored process ID would not reset and the user cannot run another test. Now, we will always set the process ID to -1 after attempting to kill MLC regardless of the result.
1 parent 33fdda4 commit da07fee

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

IMLCGui/MLCProcess.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ public Process StartProcess(string arguments)
169169

170170
public bool Stop()
171171
{
172-
bool retVal = false;
172+
bool stopped = false;
173173
if (this.CancellationTokenSource != null && !this.CancellationTokenSource.IsCancellationRequested)
174174
{
175175
this.CancellationTokenSource.Cancel();
176176
this.CancellationTokenSource = null;
177-
retVal = true;
177+
stopped = true;
178178
try
179179
{
180180
Thread.Sleep(250);
@@ -196,16 +196,12 @@ public bool Stop()
196196
Process runningProcess = Process.GetProcessById(this.ProcessId);
197197
if (runningProcess != null && !runningProcess.HasExited)
198198
{
199-
if (!runningProcess.HasExited)
199+
string processName = runningProcess.ProcessName;
200+
runningProcess.Kill();
201+
runningProcess.WaitForExit();
202+
if (this._logger != null)
200203
{
201-
string processName = runningProcess.ProcessName;
202-
runningProcess.Kill();
203-
runningProcess.WaitForExit();
204-
if (this._logger != null)
205-
{
206-
this._logger.Log($"Killed process: {processName}");
207-
}
208-
this.ProcessId = -1;
204+
this._logger.Log($"Killed process: {processName}");
209205
}
210206
}
211207
else
@@ -214,7 +210,6 @@ public bool Stop()
214210
{
215211
this._logger.Log("Killed MLC.");
216212
}
217-
this.ProcessId = -1;
218213
}
219214
}
220215
catch (Exception ex)
@@ -224,10 +219,14 @@ public bool Stop()
224219
this._logger.Error("Failed to kill MLC process:", ex);
225220
}
226221
}
227-
retVal = true;
222+
finally
223+
{
224+
this.ProcessId = -1;
225+
}
226+
stopped = true;
228227
}
229228
}
230-
return retVal;
229+
return stopped;
231230
}
232231
}
233232
}

IMLCGui/MainWindow.xaml.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public partial class MainWindow : MetroWindow
4646
private MLCProcess _mlcProcess;
4747
private AutoUpdater autoUpdater;
4848

49+
private bool runningTest = false;
50+
4951
public MainWindow()
5052
{
5153
this._logger = new Logger("imlcgui.log");
@@ -305,7 +307,11 @@ private void HandleMLCButton(Action resetUI, string logMessage, Action taskActio
305307
{
306308
if (this._mlcProcess.Stop())
307309
{
308-
return;
310+
if (this.runningTest)
311+
{
312+
this.runningTest = false;
313+
return;
314+
}
309315
}
310316
string validationResult = ValidateMLC();
311317
if (validationResult != null)
@@ -314,15 +320,15 @@ private void HandleMLCButton(Action resetUI, string logMessage, Action taskActio
314320
return;
315321
}
316322

317-
if (resetUI != null)
318-
{
319-
resetUI();
320-
}
321-
323+
this.runningTest = true;
322324
if (logMessage != null)
323325
{
324326
this._logger.Log(logMessage);
325327
}
328+
if (resetUI != null)
329+
{
330+
resetUI();
331+
}
326332

327333
this._mlcProcess.CancellationTokenSource = new CancellationTokenSource();
328334
Task.Run(taskAction, this._mlcProcess.CancellationTokenSource.Token);
@@ -436,6 +442,7 @@ private void TxtBoxQuickLatency_DoubleClick(object sender, RoutedEventArgs e)
436442

437443
private void ResetQuickRunButton()
438444
{
445+
this.runningTest = false;
439446
this.BtnQuickRun.Invoke(() =>
440447
{
441448
this.BtnQuickRun.Content = "Run";
@@ -545,6 +552,7 @@ private void BtnBandwidthRun_Click(object sender, RoutedEventArgs e)
545552

546553
private void ResetBandwidthRunButton()
547554
{
555+
this.runningTest = false;
548556
this.BtnBandwidthRun.Invoke(() =>
549557
{
550558
this.BtnBandwidthRun.Content = "Run";
@@ -698,6 +706,7 @@ private void BtnLatencyRun_Click(object sender, RoutedEventArgs e)
698706

699707
private void ResetLatencyRunButton()
700708
{
709+
this.runningTest = false;
701710
this.BtnLatencyRun.Invoke(() =>
702711
{
703712
this.BtnLatencyRun.Content = "Run";
@@ -846,6 +855,7 @@ private void BtnCacheRun_Click(object sender, RoutedEventArgs e)
846855

847856
private void ResetCacheRunButton()
848857
{
858+
this.runningTest = false;
849859
this.BtnCacheRun.Invoke(() =>
850860
{
851861
this.BtnCacheRun.Content = "Run";

IMLCGui/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.1.0.0")]
55-
[assembly: AssemblyFileVersion("1.1.0.0")]
54+
[assembly: AssemblyVersion("1.1.1.0")]
55+
[assembly: AssemblyFileVersion("1.1.1.0")]

0 commit comments

Comments
 (0)