Reputation: 151
In my form, when the user clicks a button I launch another executable. That executable displays another window on the screen.
However, when the user clicks on the button a second time, I don't want to display a second window if the first one is still open.
How can I do this?
Upvotes: 2
Views: 157
Reputation: 50712
You can disable the button, then use Process.Start and simply wait for the Exited event of the returned Process object to occur before enabling the button again.
EDIT Simply disabling the button is not a correct way of preventing the process from being started again; it is just a sign to the user that the button can't be clicked again. You should use a flag/ManualResetEvent and set it when the process starts. Check for it before starting the process and reset it in the Exited event.
Upvotes: 2
Reputation: 38087
Are you using Process.Start to launch the executable? If so, you could keep the process ID around and see if the process is still running. If it is, do nothing, if not, relaunch it.
Upvotes: 0