Task status :Waiting for activation -DownloadStringTaskAsync -WP8

不问归期 提交于 2019-12-10 21:37:09

问题


The status of task is always "Waiting for activation".The Result of the task ="". i dont understand why...Thanks for your help The 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;
        }
   } 
}     

回答1:


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


来源:https://stackoverflow.com/questions/21606017/task-status-waiting-for-activation-downloadstringtaskasync-wp8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!