Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 

Enforcing Single Application Instances in WPF with Named Pipes

See blog post.

Usage:

    public partial class App : Application
    {
        
        protected override void OnStartup(StartupEventArgs e)
        {
            // hook on error before app really starts
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            base.OnStartup(e);

            // Set a unique application ID
            Guid id = Guid.Parse("DC2A927C-AC89-4512-BB29-7AB0A18DE105");

            // Instantiate an SIA
            SingleInstanceApplication sia = new SingleInstanceApplication(id);            
            // Handle the ApplicationStarts event
            // When this event fires, initialize the application
            sia.ApplicationStarts += (sender, earg) =>
            {
                var mw = new MainWindow();
                mw.Show();
                // If another instance attempts to start, bring our window to the front
                sia.AnotherInstanceAttemptsToStart += SingleInstanceApplication.BringToFrontWhenCalled(mw);
            };
            // Optionally handle AnotherInstanceAttemptsToStart, for example, to log other attempts
            sia.AnotherInstanceAttemptsToStart += (sender, earg) =>
            {
                Logger.LogInfo("### Captured another instance trying to start");

            };
            // Run the application and single instance protection
            sia.RunSingleInstance();            

        }

About

Enforcing Single Application Instances in WPF with Named Pipes

Resources

Releases

No releases published

Packages

No packages published

Languages