Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Process Exited Event Help

Tags:

c#

process

events

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

And this is the exited method

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

How would i get the information about the process from the exited method? which of the variables (o, e) give me this data and what type are they meant to be?

like image 941
Ozzy Avatar asked Aug 13 '26 21:08

Ozzy


1 Answers

While working with .Net Base Class Library, you will find that each event passes two parameters.

First is always of type System.Object and other is of type (or descendant of) System.EventArgs.

The first argument that is object sender can be safely cast into type of class that raised that event. In your case that is of type System.Diagnostics.Process.

Example:

private void cExited(object o, EventArgs e)
{
    Process p = (Process)o;
    // Use p here
}
like image 110
decyclone Avatar answered Aug 15 '26 12:08

decyclone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!