suspending a process for a while and then resume the same process programing

98 Views Asked by At

I need to suspend a process of a local application (Windowsform) when the user tries to shut down his station, but when the user cancels the shutdown action, I need the same application to return. I want to prevent the application from appearing hanging in the message, from windows where it informs that there is a process preventing the shutdown. Thank you, gentlemen, I've been trying for a few days but without success to reproduce this behavior, thank you all very much. I'm already implementing the protected override void WndProc(ref Message m) method, which checks the constants WM_QUERYENDSESSION /WM_ENDSESSION

static void RestartApp_(int pid, string applicationName)
        {
            // Wait for the process to terminate            
            try
            {
                foreach (Process item in Process.GetProcesses())
                {
                    if (item.Id == pid)
                    {   
                        item.Kill();                        
                        
                    }
                }

            }
            catch
            {

            }
            finally
           {
                Thread.Sleep(5000);
                Process.Start(applicationName);
            }
        }

}```
1

There are 1 best solutions below

1
edu7 On

I think you can handle it, looking for the process name, and if there is one process name with the name that you specify you don't need to start again the process. Something like a background service that the only task is checking if a certain process is running or not and when is not runnig, start it again.