I have a form that functions as a menu. It starts various applications
and keeps track of those apps on whether they are open or not. I have
used both the Shell and Diagnostics.Process.Start procedures to start
the applications. Everything works fine. When an app is started, a
Process variable is used to keep track of it. I define it like this:
Private WithEvents Process1 As Process
When the process starts I make visible a button and label on the menu
form. This button is for the user to click and it will maximize the
associated application that was started. Because of the events that
Process1 raises I want to do the following:
Private Sub Process1_Exited(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Process1.Exited
lblOpenApplication1.Visible = False
btnOpenApplication1.Visible = False
End Sub
It is supposed to make the button and label associated with that app
not visible any more. But I get a "Cross-thread operation not valid"
error when the code hits the first line in the Sub above. I can
understand why. It is because Process1 is created in a different
thread than the menu form. But I don't know how to get around this
using Process1.
I realize that I could have a timer to watch for the process and see if
it still exists. But I would like to avoid that if possible. Any
thoughts?