C#异步函数不返回值

时间:2018-03-22 00:44:12

标签: c# api asynchronous

我正在使用ASYNC和JSON

集成MailChimp API

**** 1 - 来电者部分****

internal class MCReportsOverview
{
     internal async Task<ReportOverview_CampaignSpecific> CampaignSpecificOverviewAsync(string campaignId)
    {
        string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.not_applicable, SubTargetType.not_applicable, campaignId);

        var jsonTask= await BaseOperation.GetAsync<ReportOverview_CampaignSpecific>(endpoint);
        return  jsonTask;
    }
}

**** 2 - 被称为****部分

F11挂在最后一行,并且没有将值返回到#1。 数据都是正确的。被调用函数的代码是

public static async Task<T> GetAsync<T>(string endpoint) where T : class
{
    string content;
    using (HttpClient client = new HttpClient())
    {
        try
        {
            Authenticate.ClientAuthentication(client);
            content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
        }
    }

    return JsonConvert.DeserializeObject<T>(content); // F11 hangs here and doesnt return to the calling function

}

功能调用

这就是我打电话给#1

的方式
MCCampaignsOverview overview = new MCCampaignsOverview();
var yy = overview.GetCampaignByIdAsync("aaaa1111").Result;

0 个答案:

没有答案