EDN Admin
Well-known member
I have this code in Form1 :void gkh_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == System.Windows.Forms.Keys.LControlKey) || (e.KeyCode == System.Windows.Forms.Keys.RControlKey))
{
controlDown = true;
}
if (e.KeyCode == System.Windows.Forms.Keys.M && controlDown)
{
if (mf == null)
{
mf = new MagnifierMainForm(false);
mf.StartPosition = FormStartPosition.Manual;
mf.Location = Control.MousePosition;
this.Select();
}
else
{
mf.Magnifier.Close();
mf = null;
}
}
if (e.KeyCode == System.Windows.Forms.Keys.S)
{
if (startStop == false)
{
ffmp.Start("test.avi", 25);
timer1.Enabled = true;
startStop = true;
}
else
{
ffmp.Close();
timer1.Enabled = false;
startStop = false;
}
}
}
When i click on the key S it will start the process click on S again will stop the process .
This is the code in ffmpeg.cs class of the Start function : public void Start(string FileName, int BitmapRate)
{
p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte);
b = new byte[1920 * 1080 * 3]; // some buffer for the r g and b of pixels of an image of size 720p
process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = @"D
ipetestpipetestffmpegx86ffmpeg.exe";
process.EnableRaisingEvents = false;
process.StartInfo.WorkingDirectory = @"D
ipetestpipetestffmpegx86";
process.StartInfo.Arguments = @"-f rawvideo -pix_fmt bgr0 -video_size 1920x1080 -i \.pipemytestpipe -map 0 -c:v libx264 -r " + BitmapRate + " " + FileName;
process.Start();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
//ar = p.BeginWaitForConnection(EndWait,null);
p.WaitForConnection();
}
And this is the Close function in the ffmpeg.cs class
ublic void Close()
{
p.Close();
//process.Close();
}
process.Close(); dosent close the process window . In Form1 im doing timer1.Enabled = false; so the process is stop . But how do i close also the process window even if its hidden ?
I also have this in Form1
rivate void ExitApplication_Click(object sender, EventArgs e)
{
this.Close();
}
This will close the entire Form1 and the application it self but how do i make sure that it will also stop the process and close the process window too for any case that maybe it will keep working or something ?
View the full article
{
if ((e.KeyCode == System.Windows.Forms.Keys.LControlKey) || (e.KeyCode == System.Windows.Forms.Keys.RControlKey))
{
controlDown = true;
}
if (e.KeyCode == System.Windows.Forms.Keys.M && controlDown)
{
if (mf == null)
{
mf = new MagnifierMainForm(false);
mf.StartPosition = FormStartPosition.Manual;
mf.Location = Control.MousePosition;
this.Select();
}
else
{
mf.Magnifier.Close();
mf = null;
}
}
if (e.KeyCode == System.Windows.Forms.Keys.S)
{
if (startStop == false)
{
ffmp.Start("test.avi", 25);
timer1.Enabled = true;
startStop = true;
}
else
{
ffmp.Close();
timer1.Enabled = false;
startStop = false;
}
}
}
When i click on the key S it will start the process click on S again will stop the process .
This is the code in ffmpeg.cs class of the Start function : public void Start(string FileName, int BitmapRate)
{
p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte);
b = new byte[1920 * 1080 * 3]; // some buffer for the r g and b of pixels of an image of size 720p
process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = @"D

process.EnableRaisingEvents = false;
process.StartInfo.WorkingDirectory = @"D

process.StartInfo.Arguments = @"-f rawvideo -pix_fmt bgr0 -video_size 1920x1080 -i \.pipemytestpipe -map 0 -c:v libx264 -r " + BitmapRate + " " + FileName;
process.Start();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
//ar = p.BeginWaitForConnection(EndWait,null);
p.WaitForConnection();
}
And this is the Close function in the ffmpeg.cs class

{
p.Close();
//process.Close();
}
process.Close(); dosent close the process window . In Form1 im doing timer1.Enabled = false; so the process is stop . But how do i close also the process window even if its hidden ?
I also have this in Form1

{
this.Close();
}
This will close the entire Form1 and the application it self but how do i make sure that it will also stop the process and close the process window too for any case that maybe it will keep working or something ?
View the full article