I'm trying to put together a small project used for training. A user must enter an answer to the problem, given a limited time. When time is expired, the user is not credited for the answer, correct answer shown. Of course, when the user presses Next button, the correct answer should not be shown until timeout is expired. During this time the user nust enter the answer. I tried to put delay in the Next button.
Simplified code to show the problem:
using System;
using System.Threading;
using System.Windows.Forms;
namespace DelayButton
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Form MyForm = this;
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
Thread.Sleep(10000);
this.textBox1.Text = "Some answer...";
button1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Can use second button!");
CheckupAnswer(listBox1.SelectedIndex);
}
void CheckupAnswer(int answerIndex) { }
}
}
It works, but during this time the user cannot select the answer. Also, hourglass cursor is shown, but much later and not always. I don't understand why. I don't need Next button during this time, so I disable it. How come other controls do not respond?
Could anyone help me to solve delay problem?