Detect Previous Process Instances Using a Mutex, Optional in User Context
Category:C#, VB.NET, ASP.NET
Version Compatibility: Visual Basic.NET
There are several ways to check if a previous instance of your program is running, i.e. Process.GetProcessesByName(thisProcess.ProcessName. But what if your program name is not so unique? Another way would be to use a Mutex synchronization object. All the code I have seen that uses a Mutex is not Citrix or Terminal server Compatible. Mutex objects will also see programs running in another users context as a previous instance, so this code has an optional flag so that it can detect global instances of the app on the system, or in the users context. Michel Posseth [MCP]
Instructions: Copy the declarations and code below and paste directly into your VB project.