Avatar ·

How to properly create a single-instance WPF application?

Hello everyone! I'm writing a WPF application in C# and encountered a problem: if the user launches the application multiple times, multiple windows open, causing confusion and unnecessary load. I want to make it so that on subsequent launches, the application either focuses on the already open window or displays a message that the program is already running. I tried using `Process.GetProcessesByName`, but it's unreliable because there can be multiple processes with the same name. I tried searching online but found many different approaches — via `Mutex`, via `EventWaitHandle`, via `NamedPipe`. I'm a beginner and don't understand which method is considered correct and safe. Here's an example of my code (App.xaml.cs) that I'm trying to modify: ```csharp public partial class App : Application ```