|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Running Apps and Threadsand 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? Paul wrote:
Show quoteHide quote > I have a form that functions as a menu. It starts various applications You need to marshal the call back to the forms thread... Something> 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 like: ' assuming your handling this with in the form... Private Sub Process1_Exited (ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Process1.Exited If Me.InvokeRequired Then Me.Invoke (New EventHandler (Address Of Me.Process_Exited), _ New Object() {sender, e}) else lblOpenApplication1.Visible = False btnOpenApplication1.Visible = False endif end sub Here's a multipart article on the subject over on msdn: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp that is part 1 of a 3 part article. The code in the article is C#, but the concept is the same... -- Tom Shelton [MVP]
Nothing as a char of a string
How to release a free source code? Dynamically open forms, reports or call functions Copywriting or protecting your program Database update problems. How to convert a regular VB app into a service to run on a Windows 2003 server? Threading a Create Dataset method is there a way to do this Crypto Question String Tokenizing - Help! |
|||||||||||||||||||||||