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

windows forms + check if another program is running

Posted on 2011-03-09
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?
Question by:dkilby
LVL 75

Accepted Solution

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


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

    if (procs == null || procs.Length <= 0)

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

Open in new window


Author Closing Comment

ID: 35086688
thank you
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35086774
How about a blocking approach?
Process[] ps = Process.GetProcessesByName("notepad");
            if (ps.Length > 0)
                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


Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with a Crystal Report in my C#.Net application 2 26
Finding Events logs for IIS website that restarts 2 14
Finding the IIS version 5 21
SSIS On fail action 5 38
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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