I am trying to restrict my application from having multiple instances at machine level, i.e. A computer will have multiple users logging into it and this application is required to have only one instance for performance reasons. So if User A starts the application, User B should simply get a message that this application is already running on User A's account. Now before you start schooling me on processes, I already tried that, and it doesn't work because for my application to check if a similar process is running, it needs to start the process(the application), in this case, the application will never start.
I am using this to restrict multiple instances, and it works great but it only works at user level.
Microsoft.VisualBasic.ApplicationServices
public class SingleInstanceApplication : WindowsFormsApplicationBase { private SingleInstanceApplication() { base.IsSingleInstance = true; } public static void Run(Form f, StartupNextInstanceEventHandler startupHandler) { SingleInstanceApplication app = new SingleInstanceApplication(); app.MainForm = f; app.StartupNextInstance += startupHandler; app.Run(Environment.GetCommandLineArgs()); } }
Any help or advice will be much appreciated...