CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    8

    Question How to running an application just one instance at time?

    Hello.

    I need to run a windows console application (.NET, C#), but avoidding the execution another instance of the same application at same time.

    How to do that?
    Last edited by hlancelot; June 23rd, 2004 at 02:39 PM.

  2. #2
    Join Date
    Sep 2002
    Posts
    19
    Use System.Process to see if a process from the same executable file exist

  3. #3
    Join Date
    Jun 2004
    Posts
    1
    Hallo,
    try to resolve your problem with this, maybe it'll help you.
    r.

    try
    {
    bool firstInstance = false;
    System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out firstInstance);
    if(!firstInstance)
    {
    MessageBox.Show("You cannot run application twice.","Information");
    return;
    }

    Application.Run(new TableForm ());
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

  4. #4
    Join Date
    Jun 2004
    Posts
    8
    Thank you very much!

    The mutex solution works perfectly!

  5. #5
    Join Date
    Sep 1999
    Posts
    67

    Re: How to running an application just one instance at time?

    I have problem with the above code when running application in release mode?

    The firstInstance seems to be true all the time.

    Anyone having simular problems?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured