Files
Groupware/Project/Program.cs
ChiKyun Kim 81f91f0897 프로젝트 시스템 통합 및 전반적인 개선사항
- 솔루션 설정 및 프로젝트 파일 업데이트
- BaseController 최적화 (HtmlAgilityPack 의존성 제거)
- CommonController 네비게이션 메뉴에 프로젝트 추가
- JobreportController 사용자 조회 기능 및 필터링 개선
- 모든 웹 화면 UI/UX 통합 및 일관성 개선
- 프로그램 시작 시 중복 실행 감지 개선
- 각종 폼 및 데이터셋 디자이너 업데이트

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-04 15:23:41 +09:00

126 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.DirectoryServices;
using System.ServiceModel.Configuration;
using System.Threading;
using System.Diagnostics;
namespace Project
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
// COM 초기화 (WebView2 오류 방지)
System.Threading.Thread.CurrentThread.SetApartmentState(System.Threading.ApartmentState.STA);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
// AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
// 중복실행 방지 체크
if (!CheckSingleInstance())
{
return; // 프로그램 종료
}
// WebView2Runtime 압축해제와 SqlServerTypes 로드는 fWarning에서 처리
// fWarning 폼을 먼저 표시하여 실행환경 체크
using(var f = new Dialog.fSystemCheck())
{
Application.Run(f);
if (f.environmentCheckCompleted)
Application.Run(new fMain());
}
}
/// <summary>
/// 중복실행 방지 체크
/// </summary>
/// <returns>단일 인스턴스인 경우 true, 중복실행인 경우 false</returns>
static bool CheckSingleInstance()
{
string processName = Process.GetCurrentProcess().ProcessName;
Process[] processes = Process.GetProcessesByName(processName);
if (processes.Length > 1)
{
// 중복실행 감지
string message = $"⚠️ {Application.ProductName} 프로그램이 이미 실행 중입니다!\n\n" +
"동시에 여러 개의 프로그램을 실행할 수 없습니다.\n\n" +
"해결방법을 선택하세요:";
var result = MessageBox.Show(message + "\n\n예(Y): 기존 프로그램을 종료하고 새로 시작\n아니오(N): 현재 실행을 취소",
"중복실행 감지",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
// 기존 프로세스들을 종료
try
{
int currentProcessId = Process.GetCurrentProcess().Id;
foreach (Process process in processes)
{
if (process.Id != currentProcessId)
{
process.Kill();
process.WaitForExit(3000); // 3초 대기
}
}
// 잠시 대기 후 계속 진행
Thread.Sleep(1000);
return true;
}
catch (Exception ex)
{
MessageBox.Show($"기존 프로그램 종료 중 오류가 발생했습니다:\n{ex.Message}\n\n" +
"작업관리자에서 수동으로 종료해주세요.",
"오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
else
{
// 현재 실행을 취소
return false;
}
}
return true; // 단일 인스턴스
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string emsg = "Fatal Error(UHE)\n\n" + e.ExceptionObject.ToString();
Pub.log.AddE(emsg);
Pub.log.Flush();
Util.SaveBugReport(emsg);
var f = new fErrorException(emsg);
f.ShowDialog();
Application.ExitThread();
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
string emsg = "Fatal Error(ATE)\n\n" + e.Exception.ToString();
Pub.log.AddE(emsg);
Pub.log.Flush();
Util.SaveBugReport(emsg);
var f = new fErrorException(emsg);
f.ShowDialog();
Application.ExitThread();
}
}
}