473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Running Apps and Threads

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?

Apr 14 '06 #1
1 1109

Paul wrote:
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


You need to marshal the call back to the forms thread... Something
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/de...ms08162002.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]

Apr 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Brian Roberts | last post by:
I have a command line Python program that sometimes takes a bit (several minutes) to run. I want to provide an optional method for an impatient user (me!) to check the status of the program. The...
4
by: BBFrost | last post by:
Ok, We have a number of c# >> WinForms << apps deployed to our field offices. The apps are installed on individual Win 2000 workstations. The offices have broadband internet connections. ...
2
by: Brett | last post by:
Let's say some one makes the argument that instead of multi threading an application, they say it's better just to make multiple applications. The app does the same thing for different modules. ...
7
by: mircu | last post by:
Hello, What would be the best for implementing architecture that runs several, independent, scheduled or run by the user on demand task in the same time? Now in my program every task creates...
4
by: Edward W. | last post by:
Can you do multi-threading in web applications? I basically understand how to do it in winforms but am not sure about it in web apps. Can someone point me to to an exmaple or an article that...
11
by: Tyron | last post by:
Is there a possibility to run an external process (exe) in on of my C# Apps Thread? I would need that because I don't want them to run anymore when my programm crashes. Also I don't want to have...
1
by: Ralph | last post by:
Okay I have a website where the user is going to hit a button to kick off a process that is going to take a long amount of time. Is there anyway without using AJAX, or possibly a windows control on...
41
by: z | last post by:
I use Visual C 2005 to develop my programs. One in particular is crashing in very specific and hard to replicate situations, made worse by the fact it only crashes when run -outside- the dev - as...
0
by: PromisedOyster | last post by:
We are having issues with our application periodically hanging. I have a timer event already running and I would like to know the state of all the running threads (foreground and background) so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.