Hi Pintoo,
Based on my understanding, you'd like your application to be a singleton application, i.e. only one instance of your application is run at the same time. If I'm off base, please feel free to let me know.
In VB.NET, we could make a application single by selecting the 'Make single instance application' option in the Project Designer.
However, there's no such an option in C#. Fortunately, .NET2.0 has provided Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase class, which provides properties, methods, and events related to the current application and has a property called IsSingleInstance.
We could derive a class from WindowsFormsApplicationBase class and set the IsSingleInstance property to true.
The following is a sample. It requires that you add a reference to Microsoft.VisualBasic in the project.
using System.Deployment.Application;
public class Program:Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Program prog = new Program();
prog.MainForm = new Form1();
prog.Run(new string[]{});
}
public Program()
{
this.IsSingleInstance = true;
}
}
Hope this helps.
If youhave any question, please feel free to let me know.
Linda