2013-02-03 1 views
1

Visual Studio 2012, windows 양식을 사용하여 바탕 화면의 바로 가기를 클릭하십시오. 나는 바탕 화면에서 바로 가기를 클릭하면 시스템 트레이에서 응용 프로그램을 복원해야합니다.시스템 트레이에서 프로그램 복원 C#

동일한 응용 프로그램의 이중성을 방지하지만 시스템 트레이의 응용 프로그램을 열지 못하도록하는 코드입니다.

[STAThread] 
    static void Main() 
    { 
     string mutex_id = "my application"; 
     using (Mutex mutex = new Mutex(false, mutex_id)) 
     { 
      if (!mutex.WaitOne(0, false)) 
      { 
       Form1 fForm; 
       fForm = new Form1(); 
       fForm.Show(); 
       fForm.WindowState = FormWindowState.Normal; 
       fForm.ShowInTaskbar = true; 
       // MessageBox.Show("Instance Already Running!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); 
       return; 
      } 

      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      Application.Run(new Form1()); 
     } 
    } 

몇 가지 질문은 여기 stackoverflow에서 행운을 빕니다. 이 코드에서 수정해야하는 것은 무엇입니까? 미리 감사드립니다!

+0

이 질문에 대한 답변을 생각합니다 : http://stackoverflow.com/questions/4592852/restoring-window-from-the-system-tray-when-allowing-only-one-instance-of- that-pr – FrostyFire

+0

http://stackoverflow.com/a/14326291/17034 –

답변

2

뮤텍스를 사용하면이 작업을 수행 할 수 있습니다. Here은 CodePlex의 볼트 온 솔루션으로, 프로그램에 쉽게 통합 할 수 있습니다.

  • 첫 번째 인스턴스 (일명 "알림 영역")는, 첫 번째 인스턴스
  • 방지 번째 인스턴스에서 활성화 그것을
  • 복원 시스템 트레이에 최소화되어있는 경우 :이 솔루션은 다음과 같은 기능을 제공 않습니다 열기
+0

대단히 감사합니다.이 솔루션은 정말 좋습니다! :) –

관련 문제