I want to check the string value for a specified time. I set it. During this time you will press the button to change the value of the string and achieve the condition. If you did not press the button during the specified time you will not check the condition. If the time is over, the condition will not be met . When using this code, the condition is always met :( :
string value;
private void button3_Click(object sender, EventArgs e)
{
IAsyncResult result;
Action action = () =>
{
do //loop to check value through 10s
{
return;
}
while ( value == "");
};
result = action.BeginInvoke(null, null);
if(result.AsyncWaitHandle.WaitOne(10000))
//wait 10s to check response
{
listBox2.Items.Add("good"); // if response string value != ""
}
else
{
listBox2.Items.Add("bad");
// if response string value == "" or timeout
}
}
private void button4_Click(object sender, EventArgs e)
{
value = "best"; // add value
}