I have a few issues with the code below.

When the application runs, as soon as `LookingAwayResult.Text = "Yes"`, the timer starts and counts to 10. When `LookingAwayResult.Text = "No"` or `"Maybe"`, the timer should stop and reset back to 0 again, but this does not.

When the timer reaches 10, a message box appears which is what I want, but this will continue showing and spam my screen. The timer is meant to reset back to 0 after the message box appears and the application to freeze until "Ok" is selected on the message box.

It seems like my code is looping all the timer which is not what I want.

```
private void OnFaceFrameArrived(object sender, FaceFrameArrivedEventArgs e)
{
    // Retrieve the face reference
    FaceFrameReference faceRef = e.FrameReference;

    if (faceRef == null) return;

    // Acquire the face frame
    using (FaceFrame faceFrame = faceRef.AcquireFrame())
    {
        if (faceFrame == null) return;

        // Retrieve the face frame result
        FaceFrameResult frameResult = faceFrame.FaceFrameResult;

        // Display the values
        HappyResult.Text = frameResult.FaceProperties[FaceProperty.Happy].ToString();
        EngagedResult.Text = frameResult.FaceProperties[FaceProperty.Engaged].ToString();
        GlassesResult.Text = frameResult.FaceProperties[FaceProperty.WearingGlasses].ToString();
        LeftEyeResult.Text = frameResult.FaceProperties[FaceProperty.LeftEyeClosed].ToString();
        RightEyeResult.Text = frameResult.FaceProperties[FaceProperty.RightEyeClosed].ToString();
        MouthOpenResult.Text = frameResult.FaceProperties[FaceProperty.MouthOpen].ToString();
        MouthMovedResult.Text = frameResult.FaceProperties[FaceProperty.MouthMoved].ToString();

        //initilize look away timer for 10 seconds
        Timer lookAwayTimer = new Timer(interval: 10000);

        //inialize the poll tiomer for 50 ms
        Timer pollTimer = new Timer(interval: 50);

        LookingAwayResult.Text = frameResult.FaceProperties[FaceProperty.LookingAway].ToString();

        //if 10 seconds expires then show message box
        lookAwayTimer.Elapsed += (s, f) =>
        {
            MessageBox.Show("Looking is set to yes", "Looking Error", MessageBoxButton.OK);
        };

        //enable poll timer
        pollTimer.Enabled = true;

        //check if person is looking. If they are not then enable the lookAwayTimer.  If they start looking
        //then disable the timer
        pollTimer.Elapsed += (s, f) =>
        {
            Check = frameResult.FaceProperties[FaceProperty.LookingAway].ToString();

            if (Check == "Yes")
            {
                lookAwayTimer.Enabled = true;
            }
            else
            {
                lookAwayTimer.Enabled = false;
            }
        };
    }
}

```

What I am after is for the timer to be run after the person is not looking and stopped and reset back to 0 when the person is looking again.

When the timer has reached 10 seconds, the message box appears and the application freezes. The user has to select "Ok" for this box to disappear and the application to reset back to defaults.

From research, I believe maybe using a global variable or modal box would come in handy here?

I believe with a modal box this would freeze my application until the user does something with it? But this still does not solve my issues with the timer not resetting back to 0 and wanting the application to completely reset after "Ok" is selected.

I have also fond out that global variables in C# should be avoided unless necessary.

If a modal box is the answer for part of this, would I just change `MessageBox.Show` to `ShowDialog`?