Wednesday, 18 November 2015
Restrict to open Windows Forms Application another time C#.NET
Steps:
Method 1:
String thisprocessname = Process.GetCurrentProcess().ProcessName;
string appName = thisprocessnambe;
bool createdNew;
mutex = new Mutex(true, appName, out createdNew);
if (!createdNew)
{
MessageBox.Show("Application is already Running");
//app is already running! Exiting the application
return;
}
Method 2:
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
{
MessageBox.Show("Application is already running");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Home());
- Open Program.cs page from your solution.
- And use any method whatever you want.
Method 1:
String thisprocessname = Process.GetCurrentProcess().ProcessName;
string appName = thisprocessnambe;
bool createdNew;
mutex = new Mutex(true, appName, out createdNew);
if (!createdNew)
{
MessageBox.Show("Application is already Running");
//app is already running! Exiting the application
return;
}
Method 2:
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
{
MessageBox.Show("Application is already running");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Home());
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment