Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i become one window application but any budy go to task manager take it end process so my apps working close. so any idea how to Keep alive processes or preventing window app termination with immediate restart.
Posted
Comments
Ankur\m/ 19-Mar-14 7:49am    
Anyone with Administrative right can kill your process and you can't really do anything about that.

1 solution

Hi,

It's simple:

C#
private void StartProcess(string fileName)
{
    var process = new Process();
    process.StartInfo = new ProcessStartInfo(fileName);
    process.EnableRaisingEvents = true;
    process.Exited += new EventHandler(process_Exited);
    process.Start();
}

private void process_Exited(object sender, EventArgs e)
{
    MessageBox.Show("Process closed");
}


More informations about processes you will find here:
http://msdn.microsoft.com/pl-pl/library/system.diagnostics.process%28v=vs.110%29.aspx[^]

Hope it helps you.

[Update]
Sorry, I didn't read too carefuly your question. But my answer may have a solution for you. You can monitor when your application was closed and restart it . Many applications (or services) uses similar solution.

Create simple agent (monitor) application which will be started by your application. Agent (monitor) after start will find your main application process and will keep and eye for it. In case user closes your main application agent will restart it.

Or you can start your application in you main window Closed event:
C#
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
    StartProcess("Your_APP_ExePath");
}


You can save some settings to restore application state after restart.

Hope this time will really help you :)
 
Share this answer
 
v4
Comments
Marcin Kozub 19-Mar-14 9:26am    
I've updated my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900