0

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.

daniele3004
  • 13,072
  • 12
  • 67
  • 75

2 Answers2

2

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.

Sam
  • 7,252
  • 16
  • 46
  • 65
Carlos
  • 5,991
  • 6
  • 43
  • 82
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/11186026) – Andre Lombaard Feb 08 '16 at 13:53
  • "It can't be done" is not an answer? – Carlos Feb 08 '16 at 15:21
0

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.

Miquel Coll
  • 759
  • 15
  • 49