Will thepresence of clicking the message box affect program output sequence
<p>I am trying to write C# code for a memory game. I would like to present the matrix( with 3 elements) to the viewer first, then a number of options for each element, highlighting that cell at a time. User has to select the correct element from  the answer panel. The display answer matrix (defined as a task) does this. The output sequence (display matrix, display answer etc. for each element shown at first) works fine if I put a message box in the for loop of display answer task. I click after every answer show and wait for next. It works fine. But if i remove the message box ( so no click required), program stops after answer showing(for the first element).could anyone help me?
relevant code portions are:</p>

<pre><code>Mainform{
......declare number of textboxes and lables...for matrix display
}
 In the Buttonclick from the main form:
{
var firstTask = new Task(() =&gt; invokedisplaymatrix(MatrixInfoValues));

var secondTask = firstTask.ContinueWith((t) =&gt; invokedisplayblankmatrix(MatrixInfoValues));

var thirdTask = secondTask.ContinueWith((t) =&gt;invokedisplayanswermatrix(MatrixInfoValues));

var fourthTask = thirdTask.ContinueWith((t) =&gt; invokedDoselection(MatrixInfoValues));

            firstTask.Start();
}
  private void invokedisplaymatrix(object Minfo1)
        {
            lock (this)
            {
                Invoke(new displaymatrixdelegate(displaymatrix), new object[] { Minfo1 });
                Thread.Sleep(2000);
            }

        }

        private void invokedisplayblankmatrix(object Minfo2)
        {
            lock (this)
            {
                Invoke(new displayblankmatrixdelegate(displayblankmatrix), new object[] { Minfo2 });
            }

        }

        private void invokedisplayanswermatrix(object Minfo3)
        {

            lock (this)
            {
                Invoke(new displayanswermatrixdelegate(displayanswermatrix), new object[] { Minfo3 });
                // Invoke(new displaymatrixdelegate(displaymatrix),new object[] {indx});
            }
        }
..Then in the display answer matrix function:

 public void displayanswermatrix(int[] Minfo3)

        {
 foreach (int ind in FilledTextBoxID2)

            {
                foreach (Control c in splitContainer1.Panel1.Controls)
                {
                    if (c is TextBox &amp;&amp; c != null)
                    {
                        if ((boxindexL + 1) == FilledTextBoxID2[j])
                        {
                            c.BackColor = Color.OrangeRed;

                        }
                        else
                        {
                            c.BackColor = Color.MediumSpringGreen;
                        }
                       boxindexL = boxindexL + 1;
                    }

                }

                int AnswerLocation = RandomNumber(1, 5);
                int[] answeroptions=excludenumberfromarray(MatrixValues2[j]); //write a function to make random numbers between 1 and 9 excluding MatrixValues2[j]

                foreach (Control c in splitContainer1.Panel2.Controls)
                {
                    if (c is TextBox)
                    {

                        //c.Text = Convert.ToString(boxindexR);
                            //answeroptions[boxindexR]);
                        if ((boxindexR + 1) == AnswerLocation)
                        {
                            c.Text = Convert.ToString(MatrixValues2[j]); //boxindexR = boxindexR - 1;
                        }
                        else
                        {
                            c.Text = Convert.ToString(answeroptions[boxindexR]);
                        }
                       //
                       //}//placing the required number in the randomly selected box
                       boxindexR = boxindexR + 1;
                    }
                 }


                Thread.Sleep(2000);
               MessageBox.Show("hello after one number");
 j = j + 1;
                boxindexR = 0; boxindexL = 0;
            }//end of first foreach

        }//display answer matrix end
</code></pre>

<p>If I comment the message box, the interface sleeps there after the first element display.
May I know how this error comes?</p>
