How can I stop a desktop application from reopening when clicked on the taskbar icon? #16074
-
When the application is minimized, I'm looking for a way to prevent it from reopening when clicked on the taskbar icon. From what I understand, this behavior is controlled at the OS level, and while Avalonia may not directly influence it, I'm interested to know if there are any potential workarounds available. |
Beta Was this translation helpful? Give feedback.
Answered by
workgroupengineering
Jun 20, 2024
Replies: 1 comment 3 replies
-
The simplest thing to do is to check if there are any other programs running with the same name and immediately exit the current one. internal class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
var currentProcess = System.Diagnostics.Process.GetCurrentProcess(); ;
var currentId = currentProcess.Id;
var currentProcessName = currentProcess.ProcessName;
if (System.Diagnostics.Process.GetProcesses().FirstOrDefault(p => p.Id != currentId && p.ProcessName == currentProcessName) is not null)
{
return;
}
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
} There are other methods like mutext but they are not cross platform. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set
ShowInTaskbar="False"
in your Window