我有以下情况
kl.KeyDown += CheckPwd;
while(flag)
System.Windows.Forms.Application.DoEvents();
//continue other code based on "Success"
//This will be called for every keydown
void CheckPwd(object sender, KeyEventArgs e)
{
//some code here
if(....)
{
flag = true;
Success = true;
kl.KeyDown -= CheckPwd;
}
else
{
flag = true;
Success = false;
kl.KeyDown -= CheckPwd;
}
}
在这里我想避免使用Application.DoEvents()
. 我尝试使用ManualResetEvent
,但是当我调用WaitOne()
它时,它阻塞了当前线程,并导致这个,CheckPwd
没有启动。我怎样才能做到这一点?