0

I have found several solutions for creating a single instance WinForms application. I am using C# and I currently have three working versions. But, each version is missing a feature I need.

The program has to run only once, update it's view with the new command arguments (displays a file), and NOT gain focus when this happens.

  1. The version where I added a reference to the VB dll gets updated with the new document I want to load, but it gets focus. Some examples of this have a line that explicitly tells the window to go to the front of the line. My code does not have this. My code is very similar to the first example in this article.

  2. The mutex version stops when there is already a version running. (I haven't tried combining versions yet to get a handle on the running instance.) My code is similar to this.

  3. And, the named instance version does not get focus (good) but does not recognize the new command line arguments. My code resembles this.

Each one of these items has a solution that does something I need, just not all of them together.

Community
  • 1
  • 1
  • How do you have a "single" instance *and* have a view updated and not gain focus? That is multiple instances. Could you please clarify? – Peter Ritchie Sep 24 '14 at 17:38
  • 1
    Simply set the e.BringToForeground property to *false* in your event handler for the StartupNextInstance event. Easy peasy. – Hans Passant Sep 24 '14 at 18:29

0 Answers0