简体   繁体   中英

How to pause the process until the method call?

I have a console app, its run like windows app (background), but when i start app , its closed in 1 sec. I have System event SessionEnding, how to pause app to moment when this event will be called?

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; }
        }
    }
Thread.Sleep(Timeout.Infinite);

或者,如果您需要消息循环:

Application.Run();

同样,您可以使用“ 启动而不调试 ”选项执行程序,或者在方法的末尾实现Console.ReadLine()语句,然后程序将等待用户输入然后终止。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM