Prevent a dot.net app to start a second instance

  • Thread starter Thread starter Totto
  • Start date Start date
T

Totto

Hi
How do I prevent a program from beeing started more than one time.
IE. If a dot net app is already started how do I prevent a second instance
to be started ?

Tnx
Totto
 
Try this:

If
UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrent
Process.ProcessName)) > 0 Then
Return
End If

It is a VB.NET syntax.

Leon
 
Leon Chi said:
Try this:

If
UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrent
Process.ProcessName)) > 0 Then
Return
End If

It is a VB.NET syntax.

However, that fails if your app happens to have the same process name
as another app. The mutex approach as specified in the link I posted
(and which is very easy to port to VB.NET if needed) allows a virtually
arbitrary string for the name of the mutex, which is a lot less likely
to collide with a mutex from a completely unrelated app.
 
Back
Top