1

我想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.");
    }
}

但是在我执行编码之后,消息框没有出现......我错过了任何代码吗?

4

1 回答 1

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.");
    }
}
于 2012-06-17T09:58:07.010 回答