2

My app needs to check and see if it is already running when launching so it doesn't open a second time. I have a system tray icon that can make the application visible = False. Works great. However, I need to make sure the user looks at the system tray for the notifyicon if the app is already running.

Private Sub mainWindowSmall_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim p() As Process
        p = Process.GetProcessesByName("TSC Tool Box")
        If p.Count > 0 Then
            MessageBox.Show("The TSC Tool Box is already running. Check System tray!", _
            "Warning !!!", MessageBoxButtons.OK, _
            MessageBoxIcon.Error, MessageBoxDefaultButton.Button2)
            Me.Close()
        Else
            totalOnLoad()
        End If
    End Sub

VB.NET | winforms

Jeremy
  • 87
  • 2
  • 2
  • 8

1 Answers1

17

This feature is already built in to Windows Forms. Go to the project properties and click the "Single Instance Application" checkbox. There's also a StartupNextInstance event that you can handle.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Sorry for the duplicated question. Thank you for the answer @Joel. Exactly what I was looking for. – Jeremy Aug 29 '13 at 14:37