Sinisterly
[Source] Single instance app code - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: [Source] Single instance app code (/Thread-Source-Single-instance-app-code)



[Source] Single instance app code - 1llusion - 03-25-2011

Hi,

well, this isn't my creation, it is from web called: www.vbnet.cz

to find the whole thread click HERE (Note: The Language is Czech)

Okay, so, not much to tell about it... by using mutex, this will detect, if your application is already running or not. Simple as that Smile

Code:
Private appMutex As System.Threading.Mutex Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Form1.Load Dim createdNew As Boolean appMutex = New System.Threading.Mutex(False, "Unique mutex name", createdNew) If Not createdNew Then MessageBox.Show("Application is already running.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Application.Exit() End If End Sub



RE: [Source] Single instance app code - Coder-san - 03-26-2011

The easier way is to check Make single Instance application in Project Properties.
But Mutex is good for CodeDom outputs and such. Nice share. Smile