well, The simplest way to ensure that only a single instance of an application runs is to use a mutex object. For example, in the following code, the form constructor creates a mutex object and then attempts to gain access to it. If WaitOne() returns true then the current thread owns the mutex, if it returns false then the mutex is owned by another thread.
using System;
using System.Windows.Forms;
using System.Threading;
class App : Form
{
Mutex mutex;
App()
{
Text = "Single Instance!";
mutex = new Mutex(false, "SINGLE_INSTANCE_MUTEX");
if (!mutex.WaitOne(0, false))
{
mutex.Close();
mu tex = null;
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
mutex.ReleaseMute x();
base.Dispose(disposing);
}
static void Main()
{
App app = new App();
if (app.mutex != null) Application.Run(app);
else MessageBox.Show("Instance already running");
}
}
For more information , please do visit source site:
http://www.ddj.com/wind ows/184 416856
Hope it will help you out.
Answered by
Romi
, an ibibo Master,
at
11:29 AM on July 08, 2008