0
我試圖使用WebClient發送POST請求,並且我正在使用「UploadStringAsync」來阻止UI凍結。我要上傳完成後返回一個變量,但我得到了一個錯誤:在uploadstring上返回一個變量完成
try
{
List<string> results = new List<string>();
//Contact the API
using (WebClient getResults = new WebClient())
{
...
//Send the POST and get the result!
getResults.UploadStringCompleted += (sender, e) =>
{
dynamic finalResult = JObject.Parse(e.Result);//finalResults.selectedProfile.name
results.Add(finalResult.selectedProfile.name);
return (results.toArray()); //Error is here
};
getResults.UploadStringAsync(new Uri(URL), "POST", postInfo);
}
//This is what was there before: return (results.ToArray());
}
catch (Exception ex)
{
...
}
我收到的錯誤是:
Since 'System.Net.UploadStringCompletedEventHandler' returns void, a return keyword must not be followed by an object expression
你爲什麼不寫一個函數,它需要你的數組作爲參數,並在你的處理程序結束時調用它? – Brutus