NET 6 WPF Single Instance Application - "System.OperationCanceledException" in System.Private.CoreLib.dll

Patrick aka MCPat 1 Reputation point
2022-09-21T09:02:54.027+00:00

Hi,

acc. this information single-instance-wpf I already used this solution on NET Framework 4.8 and was working there and is working with NET 6.

But with VS 2022, after closing the window, I see this message twice before debugging stops. Everything is running fine, but I am not sure how to avoid this messages.

Ausnahme ausgelöst: "System.OperationCanceledException" in System.Private.CoreLib.dll
Ausnahme ausgelöst: "System.OperationCanceledException" in System.Private.CoreLib.dll

Code:

using System;  
  
namespace Net6_WPF_SingleInstance  
{  
    public class WpfPointsApp : System.Windows.Application  
    {  
        protected override void OnStartup(System.Windows.StartupEventArgs e)  
        {  
            base.OnStartup(e);  
            ShowWindow();  
        }  
        public static void ShowWindow()  
        {  
            MainWindow win = new();  
            win.Show();  
        }  
    }  
    public class SingleInstanceApplicationWrapper : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase  
    {  
        public SingleInstanceApplicationWrapper()  
        {  
            //set IsSingleInstance  
            IsSingleInstance = true;  
        }  
        private WpfPointsApp? app;  
        protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)  
        {  
            base.OnStartup(eventArgs);  
            app = new WpfPointsApp();  
            app.Run();  
            return false;  
        }  
        protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)  
        {  
            base.OnStartupNextInstance(eventArgs);  
            if(app != null)  
                WpfPointsApp.ShowWindow();  
        }  
    }  
  
    public class StartUp  
    {  
        [STAThread]  
        public static void Main(string[] args)  
        {  
            SingleInstanceApplicationWrapper wrapper = new();  
            wrapper.Run(args);  
        }  
    }  
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,663 questions
{count} votes