Skip to main content
Jamal removed the edit marker I put in which made the method irrelevant. I also added click to the start method to indicate it is a button click.
Source Link
J Dub
  • 223
  • 1
  • 7

RunTestRoutine() is called from main via a button click.

public async Task RunTestRoutine() // <----- taken out
{
     Abort = new CancellationTokenSource();
 
     int reached = await RunTestConfigReached(Abort.Token);
 
     if(reached == 0)
       {
        // Yay it completed.
       }
     else if(reached > 0)
       {
        // Boo it didn't.
        OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed",reached)));
       }
}

 private async void StartTestStartTest_Click(object sender, RoutedEventArgs e)// <---- Called directly from main
        {


            if (AdamCont == null)
            { return; }


            Abort = new CancellationTokenSource();

            int reached = await AdamCont.RunTestConfigReached(Abort.Token);

            if (reached == 0)
            {
                LightControl(SignalLight.GreenLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }
            else if (reached > 0)
            {
                LightControl(SignalLight.RedLight);                   
                Model.TestState = TestCycleState.NotInTest;
               // OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
                //Now failedPosition can be called directly.
                FailedPosition( new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
            }
            else
            {
                LightControl(SignalLight.AmberLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }

        }

RunTestRoutine() is called from main via a button click.

public async Task RunTestRoutine() // <----- taken out
{
     Abort = new CancellationTokenSource();
 
     int reached = await RunTestConfigReached(Abort.Token);
 
     if(reached == 0)
       {
        // Yay it completed.
       }
     else if(reached > 0)
       {
        // Boo it didn't.
        OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed",reached)));
       }
}

 private async void StartTest(object sender, RoutedEventArgs e)// <---- Called directly from main
        {


            if (AdamCont == null)
            { return; }


            Abort = new CancellationTokenSource();

            int reached = await AdamCont.RunTestConfigReached(Abort.Token);

            if (reached == 0)
            {
                LightControl(SignalLight.GreenLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }
            else if (reached > 0)
            {
                LightControl(SignalLight.RedLight);                   
                Model.TestState = TestCycleState.NotInTest;
               // OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
                //Now failedPosition can be called directly.
                FailedPosition( new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
            }
            else
            {
                LightControl(SignalLight.AmberLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }

        }
 private async void StartTest_Click(object sender, RoutedEventArgs e)
        {


            if (AdamCont == null)
            { return; }


            Abort = new CancellationTokenSource();

            int reached = await AdamCont.RunTestConfigReached(Abort.Token);

            if (reached == 0)
            {
                LightControl(SignalLight.GreenLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }
            else if (reached > 0)
            {
                LightControl(SignalLight.RedLight);                   
                Model.TestState = TestCycleState.NotInTest;
               // OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
                //Now failedPosition can be called directly.
                FailedPosition( new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
            }
            else
            {
                LightControl(SignalLight.AmberLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }

        }
deleted 151 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

So I feel like I'm overdoing the async await stuff. I'm just learning. Maybe this isn't the best instance to be using this stuff.

Edit from original post. I took out RunTestRoutine() and put that code directly in the button_click(), then removed the FailedEvent call.

So I feel like I'm overdoing the async await stuff. I'm just learning. Maybe this isn't the best instance to be using this stuff.

Edit from original post. I took out RunTestRoutine() and put that code directly in the button_click(), then removed the FailedEvent call.

I feel like I'm overdoing the async await stuff. I'm just learning. Maybe this isn't the best instance to be using this stuff.

added 1631 characters in body
Source Link
J Dub
  • 223
  • 1
  • 7
public async Task RunTestRoutine() // <----- taken out
{
     Abort = new CancellationTokenSource();
 
     int reached = await RunTestConfigReached(Abort.Token);
 
     if(reached == 0)
       {
        // Yay it completed.
       }
     else if(reached > 0)
       {
        // Boo it didn't.
        OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed",reached)));
       }
}

 private async void StartTest(object sender, RoutedEventArgs e)// <---- Called directly from main
        {


            if (AdamCont == null)
            { return; }


            Abort = new CancellationTokenSource();

            int reached = await AdamCont.RunTestConfigReached(Abort.Token);

            if (reached == 0)
            {
                LightControl(SignalLight.GreenLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }
            else if (reached > 0)
            {
                LightControl(SignalLight.RedLight);                   
                Model.TestState = TestCycleState.NotInTest;
               // OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
                //Now failedPosition can be called directly.
                FailedPosition( new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
            }
            else
            {
                LightControl(SignalLight.AmberLight);
                Model.InTestFlag = false;
                Model.InErrorState = false;
                Model.TestState = TestCycleState.NotInTest;
            }

        }
public async Task RunTestRoutine() // <----- taken out
{
     Abort = new CancellationTokenSource();
 
     int reached = await RunTestConfigReached(Abort.Token);
 
     if(reached == 0)
       {
        // Yay it completed.
       }
     else if(reached > 0)
       {
        // Boo it didn't.
        OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed",reached)));
       }
}

 private async void StartTest(object sender, RoutedEventArgs e)// <---- Called directly from main
        {


            if (AdamCont == null)
            { return; }


            Abort = new CancellationTokenSource();

            int reached = await AdamCont.RunTestConfigReached(Abort.Token);

            if (reached == 0)
            {
                LightControl(SignalLight.GreenLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }
            else if (reached > 0)
            {
                LightControl(SignalLight.RedLight);                   
                Model.TestState = TestCycleState.NotInTest;
               // OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
                FailedPosition( new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
            }
            else
            {
                LightControl(SignalLight.AmberLight);
                Model.InTestFlag = false;
                Model.InErrorState = false;
                Model.TestState = TestCycleState.NotInTest;
            }

        }
public async Task RunTestRoutine() // <----- taken out
{
     Abort = new CancellationTokenSource();
 
     int reached = await RunTestConfigReached(Abort.Token);
 
     if(reached == 0)
       {
        // Yay it completed.
       }
     else if(reached > 0)
       {
        // Boo it didn't.
        OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed",reached)));
       }
}

 private async void StartTest(object sender, RoutedEventArgs e)// <---- Called directly from main
        {


            if (AdamCont == null)
            { return; }


            Abort = new CancellationTokenSource();

            int reached = await AdamCont.RunTestConfigReached(Abort.Token);

            if (reached == 0)
            {
                LightControl(SignalLight.GreenLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }
            else if (reached > 0)
            {
                LightControl(SignalLight.RedLight);                   
                Model.TestState = TestCycleState.NotInTest;
               // OnFailed(this, new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
                //Now failedPosition can be called directly.
                FailedPosition( new FailedPositionEventArgs(Model.TestState, String.Format("Step {0} in test configuration failed", reached)));
            }
            else
            {
                LightControl(SignalLight.AmberLight);                   
                Model.TestState = TestCycleState.NotInTest;
            }

        }
added 1631 characters in body
Source Link
J Dub
  • 223
  • 1
  • 7
Loading
Tweeted twitter.com/StackCodeReview/status/669604837647097856
Source Link
J Dub
  • 223
  • 1
  • 7
Loading