single application instance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've read several threads about 1 single instance of application and I tried
them but without sucess.
Does anyone have a good example for making the main Form as single instance
application ?

thanks a lot,
PM
 
Hi Maileen,

Try this one.

Public Sub Main()
Dim intAppInstances As Integer
intAppInstances = UBound(Diagnostics.Process.GetProcessesByName
(Diagnostics.Process.GetCurrentProcess.ProcessName))
If intAppInstances > 0 Then
MsgBox("Only one instance can be run at a time.")
Exit Sub
End If
End Sub

Regards
Sakharam Phapale
 
Sakharam said:
Hi Maileen,

Try this one.

Public Sub Main()
Dim intAppInstances As Integer
intAppInstances = UBound(Diagnostics.Process.GetProcessesByName
(Diagnostics.Process.GetCurrentProcess.ProcessName))
If intAppInstances > 0 Then
MsgBox("Only one instance can be run at a time.")
Exit Sub
End If
End Sub

Regards
Sakharam Phapale

Shouldn't
If intAppInstances > 0 Then
be
If intAppInstances > 1 Then

Otherwise you can't even run it once since the program checking it is
itself one of the instances.
 
Sakharam Phapale said:
Try this one.

Public Sub Main()
Dim intAppInstances As Integer
intAppInstances = UBound(Diagnostics.Process.GetProcessesByName
(Diagnostics.Process.GetCurrentProcess.ProcessName))
If intAppInstances > 0 Then

The process name is not necessarily unique.
 
thanks a lot,
I just change it a little bit in order to make it more suitable.
but it helped me a lot.
 
Maileen,

Why I point you on the method from Tom is that that prevents that programs
which have the same names as yours are not blocked.

Otherwise is this more than enough
\\\
Private mut As New Threading.Mutex(True, "myProgram", mutCreated)
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not mutCreated Then Me.Close()
////

I hope this gives more ideas

Cor
 
Back
Top