question

PatrickakaMCPat-4124 avatar image
0 Votes"
PatrickakaMCPat-4124 asked PatrickakaMCPat-4124 published

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

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-wpf
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@PatrickakaMCPat-4124. Is your project a WinForm project or a WPF project? Could you show a screenshot of your project structure? Is the project .Net Framework or .Net 6?

0 Votes 0 ·

Hi @HuiLiu-MSFT
it's a WPF project (where I want to realize a single instance app which receives the args from commandline). It's .NET 6

244156-net6singleinstanceprojectstructure.png


0 Votes 0 ·
HuiLiu-MSFT avatar image HuiLiu-MSFT PatrickakaMCPat-4124 ·

Hi,@PatrickakaMCPat-4124 .Ok, I'll test it and come back with an update.

0 Votes 0 ·
Show more comments

0 Answers