Cannot await 'void' error in windows phone

2019-08-20 07:39发布

I am stuck in this problem. I am creating a Windows Phone application. Here is the code.

private async void btn_signup_Click(object sender, RoutedEventArgs e)
{
    obj = new ServiceReference2.Service1Client();

    if (!txt_id.Text.Equals("") && !txt_name.Text.Equals("") && !txt_password.Equals(""))
    {
        user r = new user();
        r.ID = txt_id.Text;
        r.FULLNAME = txt_name.Text;
        r.PASSWORD = txt_password.Text;
        var g = await obj.GetDataAsync(r);
        string message = g;

        if (message.Equals("done"))
        {
            lbl_show.Text = "you have signed up !! Hurrah";
            NavigationService.Navigate(new Uri("/mainmenu.xaml", UriKind.Relative));
        }
        else
        {
            lbl_show.Text = " Please fill all the field.Enter again";
        }
    }
}

I am getting this error "cannot await void". I am using WCF service to access the db. Please guide me with the appropriate solution.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-20 08:07

GetDataAsync is not a TAP method; it is an EAP method.

Try to re-create the WCF proxy and tell it to create TAP asynchronous methods. If Visual Studio doesn't give you that option, then see if the proxy has Begin*/End* methods that you can wrap into a TAP method.

If nothing else, you can wrap the EAP method/event into a TAP method.

查看更多
登录 后发表回答