Every once in a while, you need to open another application from your WinForm application. Today’s snippet is a wrapper which will give you the ability to start a new process (application). It takes two parameters: filename – string - the name full path of the application to open waitToFinish – bool - True/False – setting to true will cause your program to stop until the opened application finishes processing.
private static void OpenApplication(string fileName, bool waitToFinish)
{
OpenApplication(fileName, String.Empty, waitToFinish);
}
private static void OpenApplication(string fileName, string arguments, bool waitToFinish)
using (System.Diagnostics.Process prc = new System.Diagnostics.Process())
prc.StartInfo.FileName = fileName;
if (arguments.Trim().Length > 0)
prc.StartInfo.Arguments = arguments;
prc.Start();
if (waitToFinish)
prc.WaitForExit();
prc.Close();
To use them, here’s an example usage:
private void button1_Click(object sender, EventArgs e)
OpenApplication(@"c:\windows\notepad.exe", false);
MessageBox.Show("Alert that processing has continued!", "Processing..", MessageBoxButtons.OK, MessageBoxIcon.Information);
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, © Copyright 2010
E-mail