Help! Monitoring Process with Different Threads Error

P

Paul

Program A.EXE starts a new Diagnostics.Process to run program B.EXE. I
have the EnableRaisingEvents set to True. When program B.EXE exits the
Exited event fires off, just like I want it to. I can display a
message box stating that B.EXE has exited. I have searched the
Internet and have seen numerous examples of that.

However, what I want to do is enable the button on program A.EXE that
started the B.EXE program process. Below is the code:

Private Sub newProcess_Exited(ByVal sender As Object, ByVal e As
System.EventArgs) Handles newProcess.Exited
'MessageBox.Show("newProcess_Exited")
lblOpenApplication1.Enabled = True
btnOpenApplication1.Enabled = True
End Sub

But I get an "InvalidOperationException" on the
lblOpenApplication1.Enabled = True statement. The error says,
"Cross-thread operation not valid: Control 'lblOpenApplication1'
accessed from a thread other than the thread it was created on."

AAARRRRGGG! Can anyone help me?

I know that I can use a timer to monitor the state of the newProcess.
But I would like to get this to work instead.
 
P

Paul

Thanks for responding Cor!

Application A cannot use the WaitForExit. It is used to open other
applications (C, D, etc.). Application A is a menu from which users
can run a host of programs at any time. It must monitor the programs
that it opens and not allow the user to open B, C, etc. more than one
time.

Anyway, I did find what I needed. When the process application A
started has exited, it fires off the "openApplicationProcess_Exited"
sub (in my app). Since that is from a different thread, it "Invokes" a
call to the base thread to handle the button enabling and disabling.
Below is the code...

Private Delegate Sub openApplicationHasExited(ByVal processID As
Integer)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top