Program 2번 실행 방지
Program 2번 실행 방지
Main Program에서 아래 굵은 부분을 추가
static System.Threading.Mutex singleton = new System.Threading.Mutex(true, "ssPLCADS");
[STAThread]
static void Main()
{
// Prevent launching my app multiple times
if (!singleton.WaitOne(TimeSpan.Zero, true))
{
//there is already another instance running!
MessageBox.Show("Instance already running");
Application.Exit();
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
}
}
** 출처 : https://stackoverflow.com/questions/93989/prevent-multiple-instances-of-a-given-app-in-net
'컴퓨터 이야기 > c#' 카테고리의 다른 글
Text File Save Dialog (0) | 2018.06.09 |
---|---|
File Name을 선택해서 Text 파일 읽기 (0) | 2018.06.09 |
How to move and resize a form without a border? (0) | 2018.06.09 |
Form을 Drag해서 이동 (0) | 2018.06.09 |
Tray로 Form을 Icon화 하기 (0) | 2018.06.06 |
Tray로 Form을 Icon화 하기
Tray로 Form을 Icon화 하기
Form애 notifyIcon1 추가
private void Form1_Load(object sender, EventArgs e) { ContextMenu ctx = new ContextMenu(); ctx.MenuItems.Add(new MenuItem("Open", new EventHandler((s, ex) => AppearingMainForm()))); ctx.MenuItems.Add("-"); ctx.MenuItems.Add(new MenuItem("Exit", new EventHandler((s, ex) => this.Close()))); notifyIcon1.ContextMenu = ctx; } private void Form1_MinimumSizeChanged(object sender, EventArgs e) { ShownNotifyIcon(); } private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { AppearingMainForm(); } private void ShownNotifyIcon() { WindowState = FormWindowState.Minimized; notifyIcon1.Visible = true; // notifyIcon1.Icon = SystemIcons.Application; } private void AppearingMainForm() { notifyIcon1.Visible = false; this.Show(); this.WindowState = FormWindowState.Normal; } private void Form1_Resize(object sender, EventArgs e) { if (FormWindowState.Minimized == this.WindowState) { ShownNotifyIcon(); } else if (FormWindowState.Normal == this.WindowState) { AppearingMainForm(); } } private void notifyIcon1_MouseDoubleClick_1(object sender, MouseEventArgs e) { // 아이콘을 더블클릭하면 폼 화면을 보여줌 AppearingMainForm(); }
'컴퓨터 이야기 > c#' 카테고리의 다른 글
Text File Save Dialog (0) | 2018.06.09 |
---|---|
File Name을 선택해서 Text 파일 읽기 (0) | 2018.06.09 |
How to move and resize a form without a border? (0) | 2018.06.09 |
Form을 Drag해서 이동 (0) | 2018.06.09 |
Program 2번 실행 방지 (0) | 2018.06.06 |