17-10-12, 06:18 PM
كاتب الموضوع : Boutemine Oualid
السلام عليكم و رحمة الله و بركاتهسنستعمل تقنية ال Mutex
كود :
using System.Threading;
protected const string APP_UNIQUE_ID = "0F054E71-9E49-42f0-9782-A0DF741D3F8E";
[STAThread]
static void Main()
{
using (Mutex __mutex = new Mutex(false, @"Global\" + APP_UNIQUE_ID)) // unique for all sessions
//using(Mutex __mutex = new Mutex(false, APP_UNIQUE_ID)) // unique just for the current session
{
if(!__mutex.WaitOne(0, false))
{
MessageBox.Show("The application is running.");
return;
}
GC.Collect();
Application.Run(new Form1());
}
}