\\\
Public Shared Function PrevInstance() As Process
Dim c As Process = Process.GetCurrentProcess()
Dim p As Process
For Each p In Process.GetProcessesByName(c.ProcessName)
If p.Id <> c.Id Then
If p.MainModule.FileName = c.MainModule.FileName Then
Return p
End If
End If
Next p
Return Nothing
End Function
///
1) The easiet way to do it is to use the System.Diagnostics namespace.
You can call a static method to get an array of Process objects given
a name. If the list comes back with more than zero elements, then the
application is running. Here is the sample:
Note that the application name does not include the exe extention.
2) When the application comes up bind to a port on the local machine.
If it is not able to bind to a port, that means that it is already up.
At that point the application should exit. The assumption you have
hard coded a port that is not well known.
3) If possible you can take advantage of COM+. COM+ can manage object
counts. Have a look at it. I will not say anymore here because I think
the first option will work for you.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.