Sasha Dzuruk Sasha Dzuruk - 2 months ago 12
C# Question

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; }
}
}

Answer
Thread.Sleep(Timeout.Infinite);

Or, if you need a message loop:

Application.Run();
Comments