我希望在将数据泵入我的列表框之前得到e.result
。我想检查e.result
是否为空或有值。
我的编码就像这样
public Page1(string s)
{
InitializeComponent();
Service1Client proxy = new Service1Client();
proxy.FindEmployeeCompleted += new EventHandler<FindEmployeeCompletedEventArgs>(proxy_FindEmployeeCompleted);
proxy.FindEmployeeAsync(s);
}
void proxy_FindEmployeeCompleted(object sender, FindEmployeeCompletedEventArgs e)
{
if(e.Result!=null)
{
listBox1.ItemsSource = e.Result;
}
else
{
MessageBox.Show("Invalid username or password.");
}
}
但在我执行编码后,消息框没有显示... 我错过了任何代码吗?
答案 0 :(得分:1)
static void proxy_FindEmployeeCompleted(object sender, FindEmployeeCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else if (e.Result != null)
{
// you can check results here.
if (e.Result.Any())
{
listBox1.ItemsSource = e.Result;
}else
{
// empty result, show message or whatever
}
}
else
{
MessageBox.Show("Invalid username or password.");
}
}