Here g1ga user pointed to the web resource which explains how to make new instance of app not to be show in Task Manager, if app is already running. Yes, all works fine except one irritating detail - the user won't know the reason the app can't be run: there's just no some message notification that app is already running. So, when I add MessageBox.Show("The application is already running"), it eventually shows up in Task Manager. Is it possible that it wouldn't happen?
Asked
Active
Viewed 273 times
0
-
I'm not exactly sure what you are asking. Do you want there to be a notification or not? And if you want a notification, how should it be displayed? – o_weisman Jan 19 '14 at 13:22
-
Yes. The user should see some message box, which notifies him that app is already running. But g1ga's link doesn't solve the problem. If I don't include MessageBox.Show, then really it doesn't show up in Task Manager. If I use MessageBox, it appears there. So, how to notify user without app entry being in Task Manager? Thanks for answer! – JohnyL Jan 20 '14 at 04:29
-
Not sure how to technically do this although wouldn't it be a better solution if you could notify the existing application that another instance was attempted and it could then notify the user. Have a look at http://stackoverflow.com/questions/7522583/send-parameters-to-a-running-application-in-c-sharp :) – Ruskin Jan 20 '14 at 08:33
1 Answers
1
You need to notify the existing instance of the application so that it can show the MessageBox itself. I've been using this class for a long time, and it works pretty well (I don't remember where it came from originally, so I just pasted it to Gist). Basically, in the App.OnStartup
method, you call CanStart
:
if (!SingleInstanceApp.CanStart(MyAppGuid))
{
Shutdown(0);
return;
}
And when your main window is created, you register it as the main window and specify a callback method that will be called when a new instance tries to start:
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
SingleInstanceApp.RegisterMainWindow(this, OnNewInstance);
}
private void OnNewInstance(string[] args)
{
MessageBox.Show("The application is already running");
}

Thomas Levesque
- 286,951
- 70
- 623
- 758