2016-09-27 50 views
1

我有一個控制檯應用程序,它的運行像Windows應用程序(背景),但是當我啓動應用程序時,它在1秒內關閉。我有系統事件SessionEnding,如何暫停應用到這個事件將被調用的時刻?如何在程序調用之前暫停進程?

static void Main(string[] args) 
    { 
     SystemEvents.SessionEnding += new SessionEndingEventHandler(Session_Ending);} 

static void Session_Ending(object sender,SessionEndingEventArgs e) 
    { 
     switch (e.Reason) 
     { 
      case SessionEndReasons.Logoff: { Add_Log(DataCombine(0, "LogOut")); q = SendData(DataCombine(1, "LogOut")); Check(q); break; } 
      case SessionEndReasons.SystemShutdown: { Add_Log(DataCombine(0, "ShutDown")); q = SendData(DataCombine(1, "ShutDown")); Check(q); break; } 
     } 
    } 

回答

1
Thread.Sleep(Timeout.Infinite); 

或者,如果你需要一個消息循環:

Application.Run(); 
1

此外,您可以執行與程序「不開始調試」選項,或在實施Console.ReadLine()聲明你的方法結束後,你的程序將等待用戶的輸入然後終止。

+0

Console.ReadLine()不工作導致應用程序在窗口中啓動mod(後臺應用程序) –