I've got 5 tasks like this:
private async Task<List<Places>> GetPlaces()
{
Stopwatch sw = new Stopwatch();
sw.Start();
var list5 = await GetPlacesTask();
sw.Stop();
Testowybox3.Text = sw.Elapsed.ToString()+" get places times";
return list5;
}
private async Task<List<Categories>> GetCategories()
{
Stopwatch sw = new Stopwatch();
sw.Start();
var list5 = await GetCategoriesTask();
sw.Stop();
Testowybox2.Text = sw.Elapsed.ToString()+" get categories times";
return list5;
}
They differs by returned value for e.g. my second task:
private async Task<EventsInstance[]> GetDetailedData()
{
Stopwatch sw = new Stopwatch();
sw.Start();
list4 = await GetDetailedDataTask();
List<EventsListPrint> lista = new List<EventsListPrint>();
foreach (var VARIABLE in list4)
{
lista.Add(new EventsListPrint() { Date = string.Format("{0:dd.MM.yyyy}", VARIABLE.startDate.Date), Time = VARIABLE.startDate.TimeOfDay.ToString(), Category = VARIABLE.categoryId.ToString(), Where = VARIABLE.organizer.designation, What = VARIABLE.name });
}
fruitdatagrid2.ItemsSource = lista;
sw.Stop();
Testowybox.Text = sw.Elapsed.ToString()+" get detailed data times";
return list4;
}
private async Task<List<Organizers>> GetOrganizers()
{
Stopwatch sw = new Stopwatch();
sw.Start();
var list5 = await GetOrganizersTask();
sw.Stop();
Testowybox4.Text = sw.Elapsed + " get orgzanizers times";
return list5;
}
They are parsing Jsons from web. I'm collecting data from them like this:
var DetailedDataList = await GetDetailedData();
var CategoriesList = await GetCategories();
var PlacesList = await GetPlaces();
var OrganizersList = await GetOrganizers();
var EventsList = await GetEvents();
How can I assure that they're all done? I tried:
Task.WhenAll(GetDetailedData(), GetCategories(), GetPlaces(), GetOrganizers(), GetEvents());
but it seems that I cannot retrieve values then. What I really want to achieve is to create method which would be aware of successful completion of tasks and then operarate on this data in my WPF GUI. I could maybe chain them in one, but I just don't know how to do so. Everything works fine as far as I'm using one of the returned list. When trying to do linq on one list using another list, there is a chance that the another one isn't prepared yet and it simply crashes my app.