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

Re: Polling Another App by Scott

Scott
Tue Mar 11 11:27:49 CDT 2008

Scott McNair <smcnair@beachexpress.takethispartout.com> wrote in
news:Xns9A5E70B958ADdonquixote235gmailco@207.46.248.16:

> 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

Re: Polling Another App by kimiraikkonen

kimiraikkonen
Tue Mar 11 11:31:34 CDT 2008

On Mar 11, 6:06=A0pm, Scott McNair
<smcn...@beachexpress.takethispartout.com> wrote:
> Hi,
>
> I've got two applications. =A0The 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(.....) =3D false Then

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

Else

' ... More code here

End if



Hope this helps.


Re: Polling Another App by Herfried

Herfried
Tue Mar 11 18:00:14 CDT 2008

"Scott McNair" <smcnair@beachexpress.takethispartout.com> schrieb:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>