-1

Here is my code below

using System.Diagnostics;


     while (Process.GetProcessesByName("Your Program").Length == 0);
            {

                if (Checkbox.Checked)
                {
                    form2.Visible = true;
                }
                else
                {
                    form2.Visible = false;
                }
            }

My problem is when "Your Program" is not open and the checkbox is checked it does not check and causes the application to freeze. I want the program to be able to check/uncheck regardless but only open the second form when the program is running.

Another problem I had was when "Your Program" was closed the form would still show which caused more issues like trying to uncheck the checkbox but ultimately leading to more freezing of the program until I had to kill it.

James L
  • 19
  • 5

1 Answers1

0

Here is my solution this seemed to work a lot better then the while loop

 Process[] pname = Process.GetProcessesByName("Your Program");
            
             
            if (!checkbox.Checked || (pname.Length == 0))
            {
                form2.Visible = false;


            }
            else
            {
               
                form2.Visible = true;
            }

Doing this removed the error I had which works wonders for my code. Hopefully this helps someone and thanks everyone for your help :)

James L
  • 19
  • 5