+ Reply to Thread
Results 1 to 2 of 2

Thread: prevent user from opening the same application twice

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    28

    prevent user from opening the same application twice

    I'd like to prevent the user from opening the same application twice , how can i do that ?
    Last edited by reachel; 10-31-2012 at 04:09 AM.

  2. #2
    Want to prevent users from opening the same application twice for any reason ?
    I got the snippet for that.

    1- Import these DLLs
    Code:
    view sourceprint?
    using System.Runtime.InteropServices;
    using System.Windows.Forms; // to display the Message
    using System.Reflection;
    2- Inside Class Program :
    Code:
    private static readonly Mutex mutex = new Mutex(true, Assembly.GetExecutingAssembly().GetName().CodeBase);
     
    static void Main()
    {
        if (!mutex.WaitOne(TimeSpan.Zero, true))
        {
            MessageBox.Show("Another instance is already running");
            Environment.Exit(0);
        }
        else
        {
            // continue with your application
        }
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

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