Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Wednesday, 18 November 2015

Restrict to open Windows Forms Application another time C#.NET

No comments :
Steps:

  • 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());

No comments :

Post a Comment