Single instance of VB.NET application

The Process class provides functionality to track system processes in a system and to start and stop system processes. In order to determine if there are other instances of a VB.NET application running in the system , we have to get a list of all the processes running in the system and check if an instance of the application is in the list or not.

The System.Diagnostics namespace provides classes that allow you to interact with system processes, event logs, and performance counters. Process.GetProcessesByName to create an array of new Process components and associate them with all the process resources that are running the same executable file on the local computer.

The above code _process() array receiving all the associated processes. If the _process() array contains more than one instance , then we should clear the instance already exist.

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		Dim _process() As Process
		_process = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)

		If _process.Length > 1 Then
			MessageBox.Show("Multiple instancess running...")
			MessageBox.Show("Single instance only....")
		End If

	End Sub

End Class (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About