성명에서 다음 줄을 실행하기 전에 일부 값을 httpget하려고합니다. 이 호출이 반환 될 때까지 기다려야하므로 비 직렬화 값을 목록에 사용할 수 있습니다.계속 비동기 호출되지 않음
비동기 호출이 먼저 완료되기를 원했기 때문에 이것을 Task
에 랩핑했습니다. 작동하여 JSON을 성공적으로 검색합니다. 나는 그 다음 그것을 ContinueWith
블록에 넣을 수 없다. 작업이 완료 되더라도 (?) 작업이 완료되지 않는 이유는 무엇입니까?
내가 전화 했어 방법 :
Task f = Task.Run(() =>
{
var task = RetrieveDataAsync();
}).ContinueWith((antecedent) =>
{
pokemonListActivityListView.Adapter = new PokemonListAdapter(this, pokemonList);
pokemonListActivityListView.FastScrollEnabled = true;
pokemonListActivityListView.ItemClick += PokemonListActivityListViewOnItemClick;
});
RetrieveDataAsync 방법 :
private async Task RetrieveDataAsync()
{
string dataUri = "http://pokemonapp6359.azurewebsites.net/Pkmn/GetAllPokemon";
using (var httpClient = new HttpClient())
{
var uri = new Uri(string.Format(dataUri, string.Empty));
//DisplayProgressBar(BeforeOrAfterLoadState.Before, progressBarView);
var response = await httpClient.GetAsync(uri);
//DisplayProgressBar(BeforeOrAfterLoadState.After, progressBarView);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
pokemonList = JsonConvert.DeserializeObject<List<PokemonDTO>>(content);
//canPressButtons = true; //fix this when implement local db
Utilities.Utilities.ShowToast(this, "Successfully fetched data", ToastLength.Short, GravityFlags.Center);
return;
}
else
{
Utilities.Utilities.ShowToast(this, "Failed to fetch data", ToastLength.Short, GravityFlags.Center);
return;
}
}
}
왜 내 코드 내가 JSON있어 때 ContinueWith
에 들어가는되지 않는 이유는 무엇입니까? 감사!