Imports System.Diagnostics Private Sub CheckInstanceOfApp() Dim appProc() As Process Dim strModName, strProcName As String strModName = Process.GetCurrentProcess.MainModule.ModuleName strProcName = System.IO.Path.GetFileNameWithoutExtension(strModName) appProc = Process.GetProcessesByName(strProcName) If appProc.Length > 1 Then MessageBox.Show("There is an instance of this application running.", "<Application Name>") Application.Exit() Else 'MessageBox.Show("There are no other instances running.", "<Application Name>") End If End Sub
using System.Diagnostics; private void CheckInstanceOfApp() { Process[] appProc = null; string strModName = null; string strProcName = null; strModName = Process.GetCurrentProcess().MainModule.ModuleName; strProcName = System.IO.Path.GetFileNameWithoutExtension(strModName); appProc = Process.GetProcessesByName(strProcName); if (appProc.Length > 1) { MessageBox.Show("There is an instance of this application running.", "<Application Name>"); Application.Exit(); } else { //MessageBox.Show("There are no other instances running.", "<Application Name>") } }
Last Updated on October 26, 2015