C # Process Exited Event Help

Process cExe = new Process();
cExe .StartInfo.FileName = "cexe.exe";
cExe .EnableRaisingEvents = true;
cExe .Exited += this.cExited;

And this is a complete method

private void cExited(object o, EventArgs e)
{
    MessageBox.Show(/* SHOW FILE NAME HERE */);
}

How can I get information about this process from the exited method? which of the variables (o, e) gives me this data and what type should it be?

+3
source share
1 answer

While working with .Net Base Class Libraryyou will find that each event passes two parameters.

First it always has a type System.Object, and another type (or a descendant) System.EventArgs.

The first argument object sendercan be safely applied to the type of class that raised this event. In your case, this is a type System.Diagnostics.Process.

Example:

private void cExited(object o, EventArgs e)
{
    Process p = (Process)o;
    // Use p here
}
+9
source

Source: https://habr.com/ru/post/1781486/


All Articles