Detect multiple instances of the application

Detect multiple instances of the application
This Visual Basic .NET code will detect if multiple instances of the current application are running by retrieving the number of running processes with the same name.

  1. ‘If we find two or more running processes by the same name
  2. If 
    Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
  3.  ' Tell the user he can only have on instance running
  4.     MessageBox.Show("Only one instance of this program can be open at a given time""Duplicate instance detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  5.  ' Close the application
  6.     Application.Exit()
  7. End If

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top