【发布时间】:2014-09-29 02:18:06
【问题描述】:
执行 GetDataAsync 时,会在 textbox1_Leave 事件完成之前引发 textBox1_Validating 事件。我该怎么做才能防止这种情况发生?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool IsValid = true;
private async void textBox1_Leave(object sender, EventArgs e)
{
MessageBox.Show("Working");
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
IsValid = await client.CheckUser(textBox1.Text);
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if(IsValid)
MessageBox.Show("Welcome!");
else
e.Cancel = true;
}
}
【问题讨论】:
-
你不能(除非你让它同步)
-
您如何称呼这些事件?通过
TextBox? -
您是否考虑过
Leave事件可能不是最好的地方?也许如果您解释一下您要做什么,我们可以帮助您找到另一个解决方案。 -
@James 我改变了我的问题。
标签: c# .net winforms task-parallel-library async-await