There are couple of scenarios here:
You kill the application by doing "End Process" from the Processes tab. In this case, you can't do anything.
You do "End Task" from the Applications tab. You can intercept this by handling the closing event of your main form and writing this code. You can read more about close reason here.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.TaskManagerClosing)
{
}
}
Though if you absolutely want to make sure that user can't stop your application from running, you should create a separate application that keeps a watch on your application. And whenever it is killed, your application runs it again. You can check if application is running or not through following code and call this code through timer after every 10s
or any desired interval.
private bool IsProcessRunning(string name)
{
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.Contains(name))
{
return true;
}
}
return false;
}