0

I was using this single instance implementation:

http://sanity-free.org/143/csharp_dotnet_single_instance_application.html

However, It stopped working when I added a NotifyIcon and I set ShowInTaskbar = false when the window is minimized. In this state the windows doesn't get the broadcast event.

So I changed the code to find the window using EnumWindows and matching the window title, which is a flimsy solution. I tried SetProp, GetProp, but the window handled is recreated when the value in ShowInTaskbar changes. I'm in .net core so I can't use the visual basic class WindowsFormsApplicationBase.

Is there a better good simple solution for activating the first window? Hopefully without sockets, pipes and stuff like that?

rm5432
  • 327
  • 1
  • 3
  • 10
  • 1
    You can try something like this: [Run the current application as Single Instance and show the previous instance](https://stackoverflow.com/a/50555532/7444103). It uses a Mutex + UI Automation. Never tested in .Net Core WinForms. – Jimi Sep 16 '20 at 18:21
  • 1
    I remember having issues with the standard answer and enhanced it: https://stackoverflow.com/a/16522305/403671 you may want to try that. Otherwise, do you have a small reproducing project? – Simon Mourier Sep 17 '20 at 05:38
  • If I use Hide() instead of ShowInTaskbar = false, the window still receives the broadcast message and that single instance solution works. Thanks anyways. – rm5432 Sep 18 '20 at 12:32

0 Answers0