2013-03-19 3 views
2

명령 줄 인수가 전달 된 응용 프로그램이 있습니다. 일정 시간이 지나면 응용 프로그램이 처음 시작된 때와 동일한 명령 줄 인수를 전달하여 응용 프로그램을 다시 시작하려고합니다.Application.Restart() with CommandLine 인수

private void frmSetTime_Load(object sender, EventArgs e) 
{ 
    try 
    { 
     string[] cmds = System.Environment.GetCommandLineArgs(); 
     //Here i gets Command Line Arguments 
    } 
    catch (Exception ex) 
    { 
     MessageBox.show(ex.message); 
    } 
    finally 
    { 
     GC.Collect(); 
    } 
} 

public void ExecuteLogic(Object obj) 
{ 
    try 
    { 
     //My set of Statements 
     Therad.sleep(5000); 
     ExecuteLogic(obj); 
    } 
    catch (Exception ex) 
    { 
     MessageBox.show(ex.message); 
    } 
    finally 
    { 
     GC.Collect(); 
     ApplicationRestart(); 
    } 
} 

private void ApplicationRestart() 
{ 
    try 
    { 
     if (Process.GetCurrentProcess().WorkingSet64 >= 10000000) 
     {       
      Application.Restart();      
     } 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.message); 
    } 
} 

답변

4

이것은 자동으로 발생합니다. 아무 것도 변경할 필요가 없습니다. Application.Restart의 문서에서

:

이 처음 실행될 때 응용 프로그램이 원래 명령 줄 옵션을 제공 한 경우, 다시는 같은 옵션으로 응용 프로그램을 다시 시작합니다.

+0

내 응용 프로그램이 종료되었지만 다시 시작되지 않기 때문에 영향을받는 양식 폐쇄 이벤트가 있습니다. –

+0

안녕하세요, 나는 해결책을 얻습니다. 그것은 난 그냥 개인 무효 ApplicationRestart()를 는 { 이 { 을 시도 할 경우 추가 Form_closed 이벤트와 작동 { Form1.FormClosed - = 새로운 FormClosedEventHandler (Form1_FormClosed) (Process.GetCurrentProcess() WorkingSet64> = 10000000.); Application.Restart(); } } catch (예외 ex) { MessageBox.Show (ex.message); } } 또한 Form_closed 이벤트에서 프로세스를 종료하는 것을 잊지 마십시오. 도움 주셔서 감사합니다. –