by Mark Shiffer
8/4/2008 8:46:00 AM
Most that have been playing this game for a while immediately think Mutex when you want to ensure your application only runs one instance at a time. I recently came across a .NET class that provides a different approach with some added functionality. The class is WindowsFormsApplicationBase. Unfortunately that class is in the Microsoft.VisualBasic.ApplicationServices namespace, so for C# you have to dirty your code with a VB namespace. The class is pretty simple. Just create it and set IsSingleInstance to true. You then have the ability to hook to events for OnStartupNextInstance, OnShutdown, OnCreateSplashScreen, etc... Worth checking out if you have this need.