1

I am building an application with C#.

I managed to turn this into a single instance application by checking if the same process is already running.

Process[] pname = Process.GetProcessesByName("SwapCardDesktop");
        if (pname.Length < 2)
        {
            // Launch Application
        }

I intend to have another functionality in here which brings up the running instance when tried to launch again.

I tried calling ShowWindowAsync() if application is already running,

ShowWindowAsync(hWnd, 9);

But this fails to bring up the application when minimized to tray.

Any suggestions on this?

EKS
  • 5,543
  • 6
  • 44
  • 60
Immanuel
  • 329
  • 4
  • 14
  • @Immanuel - EKS's answer should be acepted. His first link is a great way to do this, much better than checking for process name. – stevehipwell Nov 05 '09 at 10:52

1 Answers1

2

Duplicated of: What is the correct way to create a single-instance application?

That points to: http://sanity-free.org/143/csharp_dotnet_single_instance_application.html

Community
  • 1
  • 1
EKS
  • 5,543
  • 6
  • 44
  • 60