Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:56:26+00:00 2026-05-15T14:56:26+00:00

I often write .net applications that only support one instance. Formerly I used .net-remoting

  • 0

I often write .net applications that only support one instance. Formerly I used .net-remoting and now WCF to detect if already an instance of my app is running and giving the focus to this instance.

My question is, if there is with .net4 a better solution available to achieve single instance applications (or is there in general a better solution available, because loading the WCF or remoting assembly at the very start of the application has a bad performance influence)

Update

Thanks for all the post. The answer to my initial question seems to be “no, there is nothing new to achieve single instance applications within .net 4”.

Thanks to all the additional information, I will change my current projects to use a Mutex to provide the desired functionality. I accepted the answer of Bob Moore because it has the most information attached to it, but thanks to all who posted useful information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:56:27+00:00Added an answer on May 15, 2026 at 2:56 pm

    The traditional way to do this is with a mutex, e.g.

    bool bNew = true; 
    using (Mutex mutex = new Mutex(true, "MYAPP_0D36E4C9-399D-4b05-BDA3-EE059FB77E8D", out bNew))
    {
       if (bNew)
       {
           // blah, blah,
           Application.Run(new MainForm());
       }
    }
    

    Edit:

    I found this code to invoke SetForegroundWindow online, so you can find the other instance of your app and bring it forward:

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);
    
    
    Process me = Process.GetCurrentProcess();
    foreach (Process process in Process.GetProcessesByName (me.ProcessName))
    {
       if (process.Id != me.Id)
       {
          SetForegroundWindow (process.MainWindowHandle);
          break;
       }
    }
    

    Note that in modern Windows implementations you can only give the foreground away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's often the case that I can write a nice tight little VB.NET function,
Short version : VB.Net Windows forms feature controls that are often dragged from the
I often write classes with a DLL export/import specification, but this seems to confuse
I often write codes in MATLAB/Python to test whether my algorithm is feasible (&
Often times I write some SQL like this: string sql = @ -- Multi-line
I'm using Squirrel SQL with Oracle. I often have to write quick queries for
Trying to write a function to see how often an object exists and give
I usually write python in emacs. I'll often want to re-evaluate my file, which
When we write a program which supports both unicode and multibytes, we often use
I use Aptana to write Python code. Aptana often report error due to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.