首页 > 解决方案 > Web服务调用在线程中失败

问题描述

我正在使用 ProgressDialog 实现一个繁忙的指示器来处理我的登录过程,是的,我知道它已经过时了,但它满足了要求。我遇到的问题是对 Web 服务的调用(是的,我知道它已折旧)失败,没有错误,什么也没有。我的代码是:

private async void MyLogon()
{
    nDialog = new ProgressDialog(this);
    nDialog.SetMessage("Validating ...");
    nDialog.SetTitle("Log On");
    nDialog.Indeterminate = false;
    nDialog.SetCancelable(true);
    nDialog.Show();

    var thread = new System.Threading.Thread(new ThreadStart(delegate
    {
        // Set the protocol
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        // Instanciate the service
        DataInterfaceWeb.DataInterface myService = new OMLDataInterfaceWeb.OMLDataInterface();
        // Fails here, cannot trap any error 
        result = myService.Logon(MyUser.Username, MyUser.Password);
    }));
    thread.Start();

    while (thread.ThreadState == ThreadState.Running)
    {
        await Task.Delay(100);
    }
}

解决这个问题的内容不多,有一篇文章建议使用awaitvis wait,但我已经使用了。有人有想法么?

标签: c#xamarinvisual-studio-2017

解决方案


推荐阅读