Get Process ID for my current application

ehelin

Freshman
Joined
Oct 11, 2005
Messages
48
Hi:

I am using single instance control, and I need to be more specific about what I'm closing. Sometimes, my application hangs...and the new instance launching thinks that it shouldn't run since it sees a process by the same name is already running. I can get around this by using the following:

Proc = Process.GetProcessesByName("MyApp")

For Each Prc As Process In Proc
Hdl = Prc.MainWindowHandle

'a value of zero means there is no visible gui
If Hdl.Equals(System.IntPtr.Zero) Then
Prc.Kill()
End If

Next

However, I will kill my application in the process...is there a way to get the process id for the instance I am trying to launch?

Eric
 
Doh!!

Answer is right in front of my face me.handle (assuming you are using a form) compared to Hdl = Prc.MainWindowHandle.

Eric
 
Back
Top