I'm trying to write a program that can be used to launch another program. I have a button, and when it's clicked, I'd like to start a program, and also record that the program has been launched. When I go to start a new program, I'd like to first check that I haven't already started the program—and if I have, close the existing instance first (so at most one instance of the program will exist at a time).
I've already written the following code:
private void button1_Click(object sender, EventArgs e)
{
bool status = false;
if (status != true)
{
status = true;
System.Diagnostics.Process.Start("C:\\Users\\David\\Desktop\\Test\\Test.exe");
}
}
Now my problem is, if I click on the button, the variable is set to false
as you can see on the first line. How I can do it correctly? Also, how I do return 0 if status is set on true?