Results 1 to 4 of 4

Thread: Process Checking

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    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!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width