1.1.1 操作被取消異常
1.1.1.1 概述
發生的異常信息如下圖所示:
1.1.1.2 原因分析
多數是因爲http請求超時造成的;
1.1.1.3 參考鏈接
https://stackoverflow.com/questions/53291880/a-task-was-canceled-xamarin-exception
Yes, oddly HttpClient throws a TaskCancelledException for request timeouts. Here's a good blog post on timeouts with HttpClient: https://www.thomaslevesque.com/2018/02/25/better-timeout-handling-with-httpclient/
HttpClient does have a Timeout property that you can set: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.timeout?redirectedfrom=MSDN&view=netframework-4.7.2
To set the timeout for all requests that use that HttpClient:
HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(200); // this is double the default
That said, it would be good to find out why your request is taking more than 100 seconds to complete. Bad network? Server overworked and responding slowly? There are many reasons why a web request might be slow.
1.1.1.4 解決方案
1.1.1.4.1 檢查接口服務是否啓動
多常見於開發時,忘記啓動接口服務
1.1.1.4.2 檢查接口超時響應的原因
1.1.1.5 總結
暫無