OKIEWARDOYO

VISUAL C# No.43 1

Jul 3rd, 2014
1,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace CobaMutex
  5. {
  6.     class Program
  7.     {
  8.         static Mutex MutexKu;
  9.  
  10.         static Boolean IsSingleInstance()
  11.         {
  12.             try
  13.             {
  14.                 //kita akan mencoba memanggil Mutex
  15.                 //yang bernama 'MediaTutorialMutex'
  16.                 Mutex.OpenExisting("MediatutorialMutex");
  17.  
  18.             }
  19.             catch (Exception)
  20.             {
  21.                 //bila 'MediatutorialMutex' tidak ditemukan
  22.                 //Maka buat Mutex Baru
  23.                 MutexKu = new Mutex(true,"MediatutorialMutex");
  24.  
  25.                 return true;
  26.             }
  27.             return false;
  28.         }
  29.         static void Main(string[] args)
  30.         {
  31.             if (!IsSingleInstance())//bila return false
  32.             {
  33.                 Console.WriteLine("IsSingleInstance bernilai False");
  34.                 Console.WriteLine("Multi instance bisa");
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine("IsSingleInstance bernilai True");
  39.                 Console.WriteLine("MultiInstance tidak bisa");
  40.             }
  41.             Console.ReadLine();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment