C#
C# 중복 실행 방지
캬옹냐옹
2021. 2. 26. 14:08
728x90

폼이 아닌 Program.cs 코드에서
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login_Form());
}
}
이렇게 되어 있는 코드를
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Process[] procs = Process.GetProcessesByName("프로세스 이름");
if (procs.Length > 1)
{
//중복 실행 방지
MessageBox.Show("'프로세스 이름'는 실행 중 입니다.");
return;
}
else
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login_Form());
}
}
}
요렇게 변경 하면 됩니다.
질행 해봤는데 잘되네요 ㅎㅎ
728x90