Click here to Skip to main content
15,886,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, I want to repetitively check if a process is running and if it is I want to kill it. So far I can make it do it once at run-time but users can run the target program (the one I want to kill) after they have run my one.

What I have tried:

I have tried
private void Form1_Load(object sender, EventArgs e)
{

    foreach (var process in Process.GetProcessesByName("TARGETPROGRAMNAME"))
    {
        process.Kill();
    }


But this only happens once upon the running of the program meaning they can run the target program after my one.
Posted
Updated 7-Jul-18 17:16pm
Comments
Patrice T 7-Jul-18 16:35pm    
Looks like a bad solution to another problem.
Dave Kreskowiak 7-Jul-18 21:56pm    
Agreed. Something fishy with this request. A bad solution for any problem.
#realJSOP 8-Jul-18 8:32am    
It's clear this guy ain't experienced enough to write code, so I'm not sure where you see the "fishy". I didn't give him code, but gave his a selection of ways to go about it.
Dave Kreskowiak 8-Jul-18 10:22am    
The "fishy" is what is he really trying to do with this? I get the feeling his experience with Windows, or any O/S really, isn't much.

The simplest way is to setup a System.Timers.Timer object to tick every n seconds, and put your code in the tick event handler.

Or, you could use TPL.

Or, you could use System.Reactive.

Or, you could use normal threads.
 
Share this answer
 
Lemmie guess, y'all wanna kill Task Manager.
 
Share this answer
 
Comments
Patrice T 8-Jul-18 1:05am    
Is it a solution ?

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