-
Process Checking
Hello everyone, new to the forum and needed some help.
I need to create a program that checks to see if a certain process is running, but I need to check it at a predetermined interval, such as every 10 seconds. I also need it to relaunch the program if it disappears/crashes.
I have no idea where to start, I'm assuming I'd have to use a timer and write a method that checks for this process and then another method to simply launch it.
-
Re: Process Checking
You are correct about the Timer. Ad one to your form, set its Interval property appropriately, then call its Start method or set its Enabled property to True.
To check whether a particular application is running, you can use the Process class. Process.GetProcessesByName will return an array of Processes with that name. If it's empty then the application is not running. You can call the Start method of the Process class to start a new process.
Once you have a Process object, you can also handle its Exited event, to be notified when the process exits.
Check out the documentation for the Process class and, in particular, those members I mentioned and see what you can come up with. If you have issues, post back and show us what you've done.
-
Re: Process Checking
I think I got most of it.
How would I launch an application in a specified directory using System.Diagnostics.Process.Start?
Thanks for your help jmcilhinney!
-
Re: Process Checking
Process.Start takes a file name/path as an argument. If you provide just the name then it will assume the working directory of the current application. That's generally a bad idea, even if that is the folder you want. You should pretty much always provide the fully-qualified path for the file you want to execute, e.g. "C:\MyFolder\MyFile.ext". How you get that path is dependent on the situation, but it will almost always not be hard-coded.