Don't allow pressing stop/abort when process not running

This commit is contained in:
Jaex 2015-09-22 21:50:41 +03:00
parent f85e75f135
commit 91fec61141
4 changed files with 25 additions and 14 deletions

View file

@ -36,6 +36,7 @@ public abstract class ExternalCLIManager : IDisposable
public event DataReceivedEventHandler ErrorDataReceived;
protected Process process;
protected bool processRunning;
public virtual int Open(string path, string args = null)
{
@ -63,7 +64,17 @@ public virtual int Open(string path, string args = null)
process.Start();
if (psi.RedirectStandardOutput) process.BeginOutputReadLine();
if (psi.RedirectStandardError) process.BeginErrorReadLine();
process.WaitForExit();
try
{
processRunning = true;
process.WaitForExit();
}
finally
{
processRunning = false;
}
return process.ExitCode;
}
}
@ -95,7 +106,7 @@ private void cli_ErrorDataReceived(object sender, DataReceivedEventArgs e)
public void WriteInput(string input)
{
if (process != null && process.StartInfo != null && process.StartInfo.RedirectStandardInput)
if (processRunning && process != null && process.StartInfo != null && process.StartInfo.RedirectStandardInput)
{
process.StandardInput.WriteLine(input);
}
@ -103,7 +114,7 @@ public void WriteInput(string input)
public virtual void Close()
{
if (process != null)
if (processRunning && process != null)
{
process.CloseMainWindow();
}

View file

@ -180,14 +180,17 @@ public DirectShowDevices GetDirectShowDevices()
public override void Close()
{
if (closeTryCount >= 2)
if (processRunning)
{
process.Kill();
}
else
{
WriteInput("q");
closeTryCount++;
if (closeTryCount >= 2)
{
process.Kill();
}
else
{
WriteInput("q");
closeTryCount++;
}
}
}
}

View file

@ -35,7 +35,6 @@ namespace ShareX.ScreenCaptureLib
public class ScreenRecorder : IDisposable
{
public bool IsRecording { get; private set; }
public bool WriteCompressed { get; set; }
public int FPS
{

View file

@ -94,9 +94,7 @@ public static void Start()
private static void CubesForm_MouseClick(object sender, MouseEventArgs e)
{
CompanionCube cube = Cubes.FirstOrDefault(x => x.Rectangle.Contains(e.Location));
if (cube != null)
foreach (CompanionCube cube in Cubes.Where(x => x.Rectangle.Contains(e.Location)))
{
cube.IsActive = false;
}