Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
' make sure that using System.Diagnostics; is included
Imports System.Diagnostics
' make sure that using System.Security.Principal; is included
Imports System.Security.Principal
Imports System.Threading
Public Class Form1
Public Sub New()
MyBase.New()
InitializeComponent()
If Not IsSingleInstance() Then
label1.Text = "There are more instance!"
Else
label1.Text = "Only one instance!"
End If
' Put label in center
End Sub
' Declare Mutex object
Public mutexx As Mutex
Public Function IsSingleInstance() As Boolean
Try
' Open existing mutex
Mutex.OpenExisting("Mutex")
Catch
' Run new instance if app don't exist
mutexx = New Mutex(True, "Mutex")
' App start normally
Return True
End Try
' Return false is app is already opened
Return False
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
No comments:
Post a Comment