2013-03-13

Sample to implement single instance (Singleton) in C#

class App : SingletonApplication
{
    private Mutex mMutex;
    protected override void OnStartup(StartupEventArgs theArgs)
    {
        bool bIsNewInstance = false;
        mMutex = new Mutex(true, "Test.SingletonApp", out bIsNewInstance);
        if(!bIsNewInstance)
        {
            App.Current.Shutdow();
        }
    }
}

No comments: