?
Solved

windows forms + check if another program is running

Posted on 2011-03-09
3
Medium Priority
?
325 Views
Last Modified: 2012-05-11
Inside a windows form is there anyway of checking to see if another program is currently running, and if it is wait 5 mins or so and then check again, and keep checking until the other application has been closed, then once closed continuing on with rest of code?
0
Comment
Question by:dkilby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35086454
Try this:
using System.Diagnostics;

...

while (true)
{
    Process[] procs = Process.GetProcessesByName("procname");  // without ".exe"

    if (procs == null || procs.Length <= 0)
    {
        break;
    }

    System.Threading.Thread.Sleep(300000);  // Sleep at least 5 minutes
}

Open in new window

0
 

Author Closing Comment

by:dkilby
ID: 35086688
thank you
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35086774
How about a blocking approach?
Process[] ps = Process.GetProcessesByName("notepad");
            if (ps.Length > 0)
            {
                ps[0].WaitForExit();
                MessageBox.Show("It was closed...");
            }

Open in new window


Or an event based approach?  
private void Foo()
        {
            Process[] ps = Process.GetProcessesByName("notepad");
            if (ps.Length > 0)
            {
                ps[0].EnableRaisingEvents = true;
                ps[0].Exited += new EventHandler(process_Exited);
            }
        }

        void process_Exited(object sender, EventArgs e)
        {
            MessageBox.Show("It was closed...");
        }

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question