Try this:
#Region "Previous Existance Function"
Private Function PrevInstance() As Boolean If UBound(System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then Return True Else Return False End If End Function
#End Region
-----------------------------
Then in Form_LOad():
If PrevInstance() = True Then MessageBox.Show("The application is already running. Press OK to exit", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End End If
----------------------------
You must use 'End' if a previous existance is found, as 'Application.Exit()' shows the form briefly when you click ok to the MessageBox & 'End' doesn't.
I hope this helps |