Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I'm trying to develop a sort of daemon that waits in the background until the user launches Outlook. Once Outlook is running, I need to kick off a procmon trace. The problem I'm having is that my program only seems to know the list of processes that were running when I initially kicked it off. What I really need is for it to re-enumerate the processes running on the system & detect whether Outlook was launched since it last checked. Here's what I currently have:

C#
class Program
    {
        static void Main(string[] args)
        {
            while (!processRunning("outlook.exe"))
                System.Threading.Thread.Sleep(10000);

            System.Threading.Thread thread = new System.Threading.Thread(DoWork);
            thread.Start();
        }

        static void DoWork()
        {
            Shell.ExecuteCommand(@"procdump.exe -ma -e Outlook.exe");
        }

        static bool processRunning(string processName)
        {
            bool found = false;
            Process[] processes = Process.GetProcesses();
            foreach (Process p in processes)
                if (p.ProcessName == processName)
                    found = true;

            return found;
        }
    }


If I launch this program when Outlook is currently running, everything is fine, and the procom trace kicks off. If I launch it before opening Outlook, it never detects that Outlook was started; Process.GetProcesses just keeps cycling through the same list of processes that it obtained when I first launched the program.

If anyone's encountered this before & knows how to resolve it, that would be much appreciated.
Posted

1 solution

I don't have any issues with below code. Should work alright.
The only difference is I used "outlook" in place of "outlook.exe"

C#
static void Main(string[] args)
    {
        int j = 0;
        while (!processRunning("outlook"))
            System.Threading.Thread.Sleep(10000);

        System.Threading.Thread thread = new System.Threading.Thread(DoWork);
        thread.Start();
    }

    static void DoWork()
    {
       Shell.ExecuteCommand(@"procdump.exe -ma -e Outlook.exe");
    }

    static bool processRunning(string processName)
    {
        Process[] processlist = Process.GetProcesses();
        var i = processlist.Where(p => p.ProcessName.ToLower().Contains("outlook"));
        return (i.Count() > 0);
    }
 
Share this answer
 
Comments
CertNerd 28-Aug-12 13:15pm    
Thank you very much! It turned out that my code was just fine except for the fact that I wasn't accounting for the process name being upper/lower case :). Sometimes, we get so wrapped up in the details, that the simplest things go right over our heads! Anyway, thanks for tipping me off!

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