//clear the current list of items and load the new items through GetItemsAsync //this is executed when the user refreshes the list async Task ExecuteLoadItemsCommand() { //the code will run only when IsBusy is false if (IsBusy) { return; } //make is busy ture so that the user can't run this twice while it is runnig IsBusy = true; Debug.WriteLine("[ExecuteLoadItemsCommand]Start loading items..."); try { //clear all the items in the list Items.Clear(); ItemGrouped.Clear(); Debug.WriteLine("[ExecuteLoadItemsCommand]Cleared items list"); //update the list only if it is connected to the internet if (CrossConnectivity.Current.IsConnected) { //get new events online, and add them to the database if there is a new one await SyncEvents.UpdateAcaEventsAsync(); } else { Debug.WriteLine("No internet connection"); } var itemsInDb = await App.Database.SortListByDate(); //add all the items to the list foreach (var item in itemsInDb) { //add items to the list Items.Add(item); } //refresh the grouped item list SetupGroup(Items); } catch (Exception ex) { await SyncEvents.SendErrorEmail(ex.Message); } finally { //set the IsBusy to false after the program finishes IsBusy = false; ScrollToEvent = true; Debug.WriteLine("[ExecuteLoadItemsCommand]There are " + Items.Count + " items in the database"); } }