What is the correct way to create a single-instance WPF application?

前端 未结 30 3104
耶瑟儿~
耶瑟儿~ 2020-11-21 05:14

Using C# and WPF under .NET (rather than Windows Forms or console), what is the correct way to create an application that can only be run as a single instance?

I kno

30条回答
  •  太阳男子
    2020-11-21 05:53

    Please check the proposed solution from here that uses a semaphore to determine if an existing instance is already running, works for a WPF application and can pass arguments from second instance to the first already running instance by using a TcpListener and a TcpClient:

    It works also for .NET Core, not only for .NET Framework.

提交回复
热议问题