无法调用事件处理程序
本文关键字:程序 事件处理 调用 | 更新日期: 2023-09-27 18:32:34
嗨,我
有一个名为GetString的WCF服务方法,我必须称它为Windows Phone App,为此我正在使用无法调用的事件处理程序。这是我的示例代码,
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MobileService1.Service1Client x = new MobileService1.Service1Client();
x.GetStringAsync();
x.GetStringCompleted += new EventHandler<MobileService1.GetStringCompletedEventArgs>(x_GetStringCompleted);
}
private void x_GetStringCompleted(object sender, MobileService1.GetStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
此x_GetStringCompleted未被调用,请帮助乡亲们...
不应为服务使用局部变量。据推测,对服务的调用在Button_Click_1方法结束之前未完成。因此,您的服务实例以及已完成的委托可能会在异步调用完成之前消失。