Polling Another App

  • Thread starter Thread starter Scott McNair
  • Start date Start date
S

Scott McNair

Hi,

I've got two applications. The job of the second application is to make
sure that the first application is running; if it's not, it relaunches it.

Is there a good code snippet that somebody can point me to that would
accomplish this?

Regards,
Scott
 
Is there a good code snippet that somebody can point me to that would
accomplish this?

As is the case a lot of times, I found the solution within a minute of
posting the question:

Private Sub CheckForApp()
Dim myProcesses() As Process
myProcesses = Process.GetProcessesByName("MyApp")
If myProcesses.Length = 0 Then
'Launch the app
System.Diagnostics.Process.Start("P:\ath\to\MyApp.exe")
End If
End Sub
 
Hi,

I've got two applications.  The job of the second application is to make
sure that the first application is running; if it's not, it relaunches it.

Is there a good code snippet that somebody can point me to that would
accomplish this?

Regards,
Scott

Scott,
I would suggest you an extraordinary method that should work for you:

With the code in that site, get an array of current processes that are
running in background (and of course your process) then add their
names into an array-compatible control like listbox.

http://www.devx.com/vb2themax/Tip/18728

Then query your application's entity by:

If lstProcesses.items.contains(.....) = false Then

system.diagnostics.process.start("<yourapplication.exe>")

Else

' ... More code here

End if



Hope this helps.
 
Scott McNair said:
I've got two applications. The job of the second application is to make
sure that the first application is running; if it's not, it relaunches it.

Take a look at the 'System.Diagnostics.Process' class, especially the
'GetProcesses' method, the 'WaitForExit' method, the 'HasExited' property,
and the 'EnableRaisingEvents' property and the 'Exited' event. You can use
'Process.Start' to start a new process.
 
Back
Top