C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,538 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
What try to do;
I have 2 Application. First App is "_Exe" and Second App is "Third". I need the program "_Exe" monitor the program "Third"
IF program "Third" start then "_Exe" raise a message" Program is Running now".
May be the program "_Exe" always running??.how to prepare the code like that.
Here some trial but I don't excatly to do.
Thank.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _Exe
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.ToLower().Contains(name.ToLower()))
{
return true;
}
}
return false;
}
private void Form1_Load(object sender, EventArgs e)
{
Process thisProc = Process.GetCurrentProcess();
if (IsProcessOpen(name : "Third"))
{
MessageBox.Show("Program is Running now");
}
else
{
//MessageBox.Show("Not Run");
}
}
}
}
To detect when a .exe is started, an usual way is with ManagementEventWatcher
(many other samples on Google, like Using WMI to monitor process creation, deletion and modification in .NET)
I noticed that you posted a new question about this, please check my reply in that thread.