Application start Running

MiPakTeh 1,476 Reputation points
2021-07-10T07:37:12.457+00:00

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");
            }
        }

    }
}
C#
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.
10,307 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,831 Reputation points
    2021-07-10T08:00:09.027+00:00

    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)