tags:

views:

35

answers:

2

Hi

I have two checkboxes and a button. Under the button click handler,

private void button1_Click(..)
{
 if(checkbox1.true) { //start a process }
 if(checkbox2.true) { //start process 2 once process 1 is done}

}

Both process 1 and 2 are started asynchronously. How do i set the dependency between process 2 and process 1? I do not want to poll if process 1 is done before starting process 2. That would block the UI. ANy other solution?

THanks

+1  A: 

You can hook up on the Exited event of the Process class.

Something along the lines of:

Process p = ...
if(checkbox2.Checked)
    p.Exited = ... // Event handler that starts process 2

p.Start()
klausbyskov
+1  A: 

Implement a background worker to do process1

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

In your runworker completed event check to see if checkbox 2 is checked

//copy and pasted from msdn

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
                    if (e.Cancelled == true)
                    {
                        //dosomething
                    }
                    else if (e.Error != null)
                    {
                        //dosomething
                    }
                    else
                    {
                        if(checkbox2.Checked)
                        {
                           //fire off process 2
                         }
                    }
                }
Dave Hanson