Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace CobaMutex
- {
- class Program
- {
- static Mutex MutexKu;
- static Boolean IsSingleInstance()
- {
- try
- {
- //kita akan mencoba memanggil Mutex
- //yang bernama 'MediaTutorialMutex'
- Mutex.OpenExisting("MediatutorialMutex");
- }
- catch (Exception)
- {
- //bila 'MediatutorialMutex' tidak ditemukan
- //Maka buat Mutex Baru
- MutexKu = new Mutex(true,"MediatutorialMutex");
- return true;
- }
- return false;
- }
- static void Main(string[] args)
- {
- if (!IsSingleInstance())//bila return false
- {
- Console.WriteLine("IsSingleInstance bernilai False");
- Console.WriteLine("Multi instance bisa");
- }
- else
- {
- Console.WriteLine("IsSingleInstance bernilai True");
- Console.WriteLine("MultiInstance tidak bisa");
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment