简体   繁体   中英

Can't Invoke EventHandler

Hi I 've an WCF Service Method named GetString, I've to call it Windows Phone App, For that I'm using a EventHandler that cant be invoked.. Here is my sample code,

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);
    }

This x_GetStringCompleted is not invoked, Plz help Folks...

You shouldn't use a local variable for your service. Presumably the call to the service isn't done before the end of the Button_Click_1 method. So your service instance and therefore the completed delegate might be gone before the async call has finished.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM