Try this:
if( processlist.Any( p => !p.HasExited ) )
{
MessageBox.Show("Outlook Opened");
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am writing a code to such that I will get a trigger when ever outlook opens
Process[] processlist = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
if (processlist.Count() > 0)
{
MessageBox.Show("Outlook Opened");
}
Works great for the first time when I open outlook, but the message box continue to show even after outlook is closed .
I also checked the background process there is no outlook process running. Help appreciated :) .
Try this:
if( processlist.Any( p => !p.HasExited ) )
{
MessageBox.Show("Outlook Opened");
}
Hi,@Rohit Pawar.Welcome to Microsoft Q&A Forum, To address this issue, you might consider using the Exited event of the Process class to handle the event when Outlook is closed. Here is an example of how to modify your code to include event handling for the Exited event:
Process[] processlist = Process.GetProcessesByName(processName);
if (processlist.Length > 0)
{
MessageBox.Show("Outlook Opened");
foreach (Process process in processlist)
{
process.EnableRaisingEvents = true;
process.Exited += OutlookExited;
}
}
private static void OutlookExited(object sender, EventArgs e)
{
MessageBox.Show("Outlook Closed");
}
If you still have questions, please feel free to let me know. The problem will be better solved if more details are described (steps, error messages, and code to reproduce the problem).
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.