gpt4 book ai didi

c# - 异步方法的返回类型必须为 void、Task 或 Task

转载 作者:太空狗 更新时间:2023-10-29 18:03:52 25 4
gpt4 key购买 nike

<分区>

我这里有以下代码:

public async Dictionary<string, float> GetLikelihoodsAsync(List<string> inputs)
{
HttpClient client = new HttpClient();

string uri = GetUri();
string body = GetRequestBody(inputs);
byte[] requestData = Encoding.UTF8.GetBytes(body);

Dictionary<string, float> result = await GetResponseAsync(requestData, client, uri)
.ContinueWith(responseTask => ParseResponseAsync(responseTask.Result))
.ContinueWith(task => task.Result.Result);

return result;
}

async Task<HttpResponseMessage> GetResponseAsync(byte[] requestData, HttpClient client, string uri) {...}

async Task<Dictionary<string, float>> ParseResponseAsync(HttpResponseMessage response) {...}

基本上在 GetResponseAsync 完成后,我想获取结果并将其提供给 ParseResponseAsync 并获得包含其结果的任务。

目前,它给出一个编译器错误提示

The return type of an async method must be void, Task or Task

实现此目标并消除此错误的最佳方法是什么?欢迎其他(更好的解决方案),也欢迎解释为什么在最后一个 ContinueWith 中执行 task.Result.Result

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com