本文介绍了任务状态:等待​​激活-DownloadStringTaskAsync -WP8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务的状态始终是等待激活的任务=的。结果。
我不明白为什么......感谢您的帮助
用户界面调用GetDocLibs方法。

 公共类ServerFunctions
{
    公共静态列表< BdeskDocLib> GetDocLibs(布尔onlyDocLibPerso)
    {
        字符串xmlContent =的getXML();
        清单< BdeskDocLib>结果= BdeskDocLib.GetListFromXml(xmlContent,onlyDocLibPerso);
        返回结果;
    }   私人静态字符串的getXML()
    {
        任务<串GT;任务= requesteur.Query(dataRequestParam);
        task.Wait();
        xmlResult = task.Result;
        返回xmlResult;
    }
}公共类DataRequest
{
    公共任务<串GT;查询(DataRequestParam dataRequestParam)
    {
       尝试
       {
        Web客户端的Web =新的WebClient();
        如果(!string.IsNullOrEmpty(dataRequestParam.AuthentificationLogin))
        {
            System.Net.NetworkCredential帐户=新的NetworkCredential(dataRequestParam.AuthentificationLogin,dataRequestParam.AuthentificationPassword);
            web.Credentials =账户;
        }
        返回web.DownloadStringTaskAsync(dataRequestParam.TargetUri).ConfigureAwait(假);
     }
 赶上(引发WebException我们)
        {
            MessageBox.Show(we.Message);
            返回null;
        }
   }
}


解决方案

我所有的方法必须是异步。

 公共类ServerFunctions
{
    公共静态异步任务<名单,LT; BdeskDocLib>> GetDocLibs(布尔onlyDocLibPerso)
    {
        字符串xmlContent =等待的getXML();
        清单< BdeskDocLib>结果= BdeskDocLib.GetListFromXml(xmlContent,onlyDocLibPerso);
        返回结果;
    }   私人异步静态任务<串GT;的getXML()
    {
        任务<串GT;任务= requesteur.Query(dataRequestParam);
        task.Wait();
        xmlResult = task.Result;
        返回xmlResult;
    }
}

The status of task is always "Waiting for activation".The Result of the task ="".i dont understand why...Thanks for your helpThe UI calls the GetDocLibs method.

public class ServerFunctions
{
    public static List<BdeskDocLib> GetDocLibs(bool onlyDocLibPerso)
    {
        string xmlContent = GetXml();
        List<BdeskDocLib> result = BdeskDocLib.GetListFromXml(xmlContent,  onlyDocLibPerso);
        return result;
    }

   private static String GetXml()
    {
        Task<String>task=requesteur.Query(dataRequestParam);
        task.Wait();
        xmlResult = task.Result;
        return xmlResult;
    }
}

public class DataRequest
{
    public Task<String> Query(DataRequestParam dataRequestParam)
    {
       try
       {
        WebClient web = new WebClient();
        if (!string.IsNullOrEmpty(dataRequestParam.AuthentificationLogin))
        {
            System.Net.NetworkCredential account = new NetworkCredential(dataRequestParam.AuthentificationLogin, dataRequestParam.AuthentificationPassword);
            web.Credentials = account;
        }
        return  web.DownloadStringTaskAsync(dataRequestParam.TargetUri).ConfigureAwait(false);
     }
 catch(WebException we)
        {
            MessageBox.Show(we.Message);
            return null;
        }
   }
}
解决方案

All my methods need to be async.

public class ServerFunctions
{
    public static async Task<List<BdeskDocLib>> GetDocLibs(bool onlyDocLibPerso)
    {
        string xmlContent = await GetXml();
        List<BdeskDocLib> result = BdeskDocLib.GetListFromXml(xmlContent,  onlyDocLibPerso);
        return result;
    }

   private async static Task<String> GetXml()
    {
        Task<String>task=requesteur.Query(dataRequestParam);
        task.Wait();
        xmlResult = task.Result;
        return xmlResult;
    }
}

这篇关于任务状态:等待​​激活-DownloadStringTaskAsync -WP8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:54