Programming/C#

Mutex를 이용한 Application 중복실행 방지

blueasa 2010. 6. 3. 16:54

using System;
using System.Windows.Forms;
using System.Threading; // Mutex를 사용하려면 반드시 포함시켜야 합니다.

namespace Test
{
       ///
       /// Test를 위한 UI입니다.
       ///

       public class FormTest : System.Windows.Forms.Form
       {

              //-----------------(중략)-----------------

              ///
              /// 해당 응용 프로그램의 주 진입점입니다. -> 중복 실행 방지
              ///

              [STAThread]
              static void Main()
              {
                     bool bNew;

                     Mutex mutex = new Mutex(true, "Test", out bNew);

                     // 한번만 실행되도록...
                     if (bNew)
                     {
                            Application.EnableVisualStyles();
                            Application.Run(new FormTest());
                            mutex.ReleaseMutex();
                     }
              }

              //-----------------(중략)-----------------

       }
}


//------------------------------------------------------------------------


반응형