This library allows you to create single instance applications.
Use Asjc.*
instead of AS.*
and AsUtils.*
!
Call the SingletonApp.Check
method at an appropriate place. It will return a bool indicating whether the application is a new instance.
// WPF
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (!SingletonApp.Check())
Shutdown();
}
Don't forget to call the SingletonApp.Cleanup
method when the application is closed!
Do not call the SingletonApp.Check
method repeatedly. Use SingletonApp.IsNew
instead, unless you are fully aware of what you are doing.
bool result1 = SingletonApp.Check(); // True
bool result2 = SingletonApp.IsNew; // True
bool result3 = SingletonApp.Check(); // False
bool result4 = SingletonApp.IsNew; // False