Check for Previous Instance of an Application Using Mutex (VB.NET)

Category:
C#, VB.NET, ASP.NET
Type:
Snippets
Difficulty:
Beginning
Author:
Intelligent Solutions Inc.

Version Compatibility: Visual Basic.NET

More information:
This shows one way to check for a previous instance of an appication in vb.net; another is at http://www.freevbcode.com/ShowCode.Asp?ID=5333. Here the app opens a named mutex object. If the second instance of the app tries and fails to gain access to the mutex via the WaitOne method, it means that the mutex is owned by the first app. When you close the first instance, the mutex is automatically disposed of by the garbage collector.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: