Here is the code I am using (although it does not bring the "running
instance to the front", sounds like a good idea).
Option Strict On
Imports System.Threading
Module Main
Private Sub SubMain()
SingletonApp.Run(New MyForm)
End Sub
Enc Module
Public Class SingletonApp
Shared m_Mutex As Mutex
Public Shared Sub Run(ByVal mainForm As Form)
If (IsFirstInstance()) Then
AddHandler Application.ApplicationExit, AddressOf OnExit
Application.Run(mainForm)
End If
End Sub
Public Shared Function IsFirstInstance() As Boolean
' use this to create a unique guid for your app...
'Dim g As New Guid
'g = Guid.NewGuid
'Debug.WriteLine(g.ToString)
m_Mutex = New Mutex(False, "8ca35a66-6e9a-41d4-a87d-d9755b1f88c4") '
arbitrary GUID
Dim owned As Boolean = False
owned = m_Mutex.WaitOne(TimeSpan.Zero, False)
Return owned
End Function
Public Shared Sub OnExit(ByVal sender As Object, ByVal args As
EventArgs)
m_Mutex.ReleaseMutex()
m_Mutex.Close()
End Sub
End Class
HTH,
Greg
"Luis Mendes" <an*******@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
Hello,
I want to make an aplication that runs only one time.
Let me explain better, each time I click on 'calculator' icon, it will
open several 'calculators'.
What I want to do is to make a aplication that, if I click is icon it will
open the aplication, if the aplication is already open it will 'bring it to
front' instead of open a new aplication.
Thank's in advance
Luis Mendes