private void PAGE_CHAT_Loaded(object sender, RoutedEventArgs e) { Lb_Chat.Items.Clear(); while (state == true) { client.LoadChat(_selectedChat.Id); state2 = true; while (state2 == true) { while (client.IsDone == true) { ChatList = client.LoadinChat(); foreach (var item in ChatList) { TextBlock txtBlock = new TextBlock(); txtBlock.TextWrapping = TextWrapping.Wrap; txtBlock.Text = $"{item.SendDate}: {item.Username}: {item.Text}"; Lb_Chat.Items.Add(txtBlock); } ChatList.Clear(); client.ClearList(); state2 = false; state = false; client.IsDone = false; } } } Task task = Task.Run((Action)CheckForUpdate); }