Advertisement
OKIEWARDOYO

VISUAL C# No.43 4

Jul 3rd, 2014
1,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using System.Threading;
  6.  
  7. namespace GuiMutex
  8. {
  9.     static class Program
  10.     {
  11.         /// <summary>
  12.         /// The main entry point for the application.
  13.         /// </summary>
  14.         [STAThread]
  15.         static void Main()
  16.         {
  17.             string MutexName = "MediatutorialMutex";
  18.             using (Mutex MutexKu = new Mutex(false, @"Global\" + MutexName))
  19.             {
  20.                 if (!MutexKu.WaitOne(0, false))
  21.                 {
  22.                     MessageBox.Show("Instance already running");
  23.                     return;
  24.                 }
  25.  
  26.                 GC.Collect(); //Garbage Collector
  27.                 Application.Run(new Form1());
  28.             }
  29.  
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement