【问题标题】:Can't Invoke EventHandler无法调用事件处理程序
【发布时间】:2013-09-23 07:23:14
【问题描述】:

您好,我有一个名为 GetString 的 WCF 服务方法,我将其命名为 Windows Phone 应用程序,为此我正在使用无法调用的 EventHandler。这是我的示例代码,

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 没有被调用,请大家帮忙...

【问题讨论】:

    标签: c# wcf events windows-phone-8 event-handling


    【解决方案1】:

    您不应该为您的服务使用局部变量。大概在 Button_Click_1 方法结束之前没有完成对服务的调用。因此,您的服务实例以及完成的委托可能在异步调用完成之前就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      • 2021-06-27
      相关资源
      最近更新 更多