开发者

C# Process Exited Event Help

开发者 https://www.devze.com 2023-01-31 20:46 出处:网络
Process cExe = new Process(); cExe .StartInfo.FileName = \"cexe.exe\"; cExe .EnableRaisingEvents = true;
Process cExe = new Process();
cExe .StartInfo.FileName = "cexe.exe";
cExe .EnableRaisingEvents = true;
cExe .Exited += this.cExited;

And t开发者_StackOverflow社区his 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?


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消