Ich bekomme AggregateException während client.PostAsyc aufrufen, auch ich habe lange Timeout festgelegt.Wie verwalten AggregateException wirft während PostAsync-Aufruf?
Hier ist mein Code.
try
{
StoresList objlist = new StoresList();
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.ApplicationDataContainer session = Windows.Storage.ApplicationData.Current.RoamingSettings;
var contents = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("userapi", session.Values["userapi"].ToString()),
new KeyValuePair<string, string>("keyapi", session.Values["keyapi"].ToString()),
new KeyValuePair<string, string>("notification_flag","1"),
new KeyValuePair<string, string>("token", localSettings.Values["deviceid"].ToString()),
});
using (var client = new HttpClient() { Timeout = TimeSpan.FromMinutes(4) })
{
var result = client.PostAsync(session.Values["URL"] + "/abcd/", contents).Result;
if (result.IsSuccessStatusCode)
{
string data = result.Content.ReadAsStringAsync().Result;
if (data.Contains("activate") || data.Contains("enable"))
{
//Please activate the Mobile Assistant Extension
return null;
}
if (data != null)
{
List<Stores> objStores = JsonConvert.DeserializeObject<LoginResponse>(data).stores;
foreach (var item in objStores)
{
Stores objs = new Stores();
{
objs.id = item.id;
objs.name = item.name;
objlist.Add(objs);
}
}
}
}
}
return objlist;
}
catch (Exception ex)
{
throw ex;
return null;
}
Kann jemand vorschlagen, wie man das bewerkstelligt? Irgendwann bekomme ich AggregateException.
Ich habe folgenden Link verwiesen, aber ich bekomme immer noch Fehler. Event Ich habe Timeout eingestellt.
How can I tell when HttpClient has timed out?
AggregateException is throwing while waiting for PostAsJsonAsync
Whats the difference between HttpClient.Timeout and using the WebRequestHandler timeout properties?