Visual Basic Non-Restart Check If Application is Open

In Visual Basic, if our application is open, we may need to set a check to prevent it from reopening.

Below is the sample code for this control..

Module ModuleTest Sub Main() Dim prcess As Process = Process.GetCurrentProcess() Dim prcessList As Process() = Process.GetProcessesByName(prcess.ProcessName) If prcessList.Length > 1 Then Console.WriteLine("App is Open") Return End If Console.ReadLine() End Sub End Module

In the example, we first find the process name of the application with our GetCurrentProcess method. Then we get all the processes running in the system according to this name and we collect it in your prcessList array variable.

If a process with this name is already running in the system, its number will be 2 with the current process. Since we only want 1 process to run, we give a warning if the number in our array variable meets the greater than 1 condition.



You May Interest

Visual Basic Finding the Computer Name

Visual Basic Reverse Array

Visual Basic Get Now

Visual Basic Randomly Shuffle a List

Visual Basic Adding Elements to List