On 2003-11-06, Alex G. <ag******@ga.com.mx> wrote:
some one knows how to check if my app. (Example ap1.exe)
is running (because i don't want than it run twice at the
same time in the same machine)
somebody knows like verifying if my application at the
moment this executing itself, since I do not want that
the application runs twice in the same computer at the
same time
Start your application from a Sub Main, then you can do something like
the following:
Option Strict On
Option Explicit On
Imports System.Threading
....
Public Sub Main()
Dim firstInstance As Boolean
Dim mut As New Mutex(True, "myuniquemutexname", firstInstance)
If firstInstance Then
Try
' start your main form
Application.Run(New MainForm())
Catch
' Handle problems
Finally
' make sure the mutext is released
mut.ReleaseMutex()
End Try
Else
MessageBox.Show("App already running")
End If
End If
Just make sure that "myuniquemutexname" is unique and known to your
program. A mutex is a global kernel object, and so can be referenced by
all applications by using the unique name. If your application is given
ownership of the mutex, then firstInstance will be true - otherwise,
your app is already running :)
--
Tom Shelton
MVP [Visual Basic]