Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(S|AS)yncronous process & Exited event

Status
Not open for further replies.

beardudeguy

Programmer
Joined
Dec 11, 2005
Messages
1
Location
US
Im trying to start a process asyncronously and then run other code, but use the System.Diagnostics.Process.Exited (or other method) to go back and restart it if it closes.

this is waht i came up with, but exited doesnt get called even if i close the program (notepad) that is started

Code:
public class pcntrl
{
    private System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
    private System.Diagnostics.Process cmd = new System.Diagnostics.Process();

    public pcntrl(string filename, string args)
    {
        this.psi.FileName = filename.ToString();
        this.psi.Arguments = args.ToString();           
    }

    public void start()
    {
        this.cmd.EnableRaisingEvents = true;

        this.cmd.Exited += new System.EventHandler(this.exited);

        this.cmd = System.Diagnostics.Process.Start(this.psi);

        this.cmd.PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal;
    }

    private void exited(object sender, EventArgs e)
    {
        Console.WriteLine("exited called");
    }
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top