In C# it's possible to block the Kill() process by another(user or program) ??
I want to close my application only by the "Close Button" and block other way.
In C# it's possible to block the Kill() process by another(user or program) ??
I want to close my application only by the "Close Button" and block other way.
I've used C# for years and I've never come across such a mechanism. You would need some way to tell the OS that the current process is somehow protected from being killed. It's maybe more of an OS question than a language question, actually.
The only way to do it is to create a Windows Service instead of a simple Process. This way, I think you could tell in the Windows services tab to always have it active and execute it as much as you would like. For instance:
protected override void OnStart(string[] args)
{
timer = new Timer();
timer.Interval = 12000; //Execute the process every 12 seconds
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
timer.Enabled = true;
}
private void timer_Tick(object sender, ElapsedEventArgs e)
{
try {
Runner.WriteErrorLog("Timer ticked and some job has ben called!");
Runner.Start();
Runner.WriteErrorLog("Job done!!");
}
catch (Exception ex)
{
Runner.WriteErrorLog("ERROR!!! " + ex.Message);
}
}
This WOULD NOT prevent the termination of your process but it would enable you to read the log and find if it has been terminated and re-launch it.