dotnet / dotnet/wpf

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

Open
#7,525 1 comment 0 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/NET-6-WPF-Single-Instance-Application---/10153919)._

---
Hi,

acc. this information [single-instance-wpf](https://social.msdn.microsoft.com/Forums/vstudio/en-US/e076b14a-3a99-46bb-986f-92c90567aa5e/single-instance-wpf?forum=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);
}
}
}
```

---
### Original Comments

#### Feedback Bot on 9/21/2022, 07:14 PM:

(private comment, text removed)
#### Dolly Wang [MSFT] on 9/22/2022, 03:03 AM:

(private comment, text removed)
#### Patrick Wallner on 9/23/2022, 01:51 AM:

(private comment, text removed)
#### Feedback Bot on 9/26/2022, 01:28 AM:

(private comment, text removed)
#### Feedback Bot on 1/4/2023, 10:31 PM:

(private comment, text removed)

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.