أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
s correct if your asynchronous work (Task.Delay) is meaningless. The difference is that a synchronous handler is completed immediately (synchronously), so the form cannot possibly close before textBox is updated.
Run Multiple Operations and Queue the Output
The app starts another asynchronous operation each time that the user chooses the Event and all the operations run to completion. All the requested operations list asynchronously, but the output from the operations is presented sequentially. The list of results for each group is presented separately.
The operations share a global Task, pendingWork, which serves as a gatekeeper for the display process.
private async void StartButton_Click(object sender, RoutedEventArgs e) { // ***Verify that each group's results are displayed together, and that // the groups display in order, by marking each group with a letter. group = (char)(group +1); ResultsTextBox.Text += string.Format("\\r\\n\\r\\n#Starting group {0}.", group); try { // *** Pass the group value to AccessTheWebAsync. char finishedGroup = await AccessTheWebAsync(group); // The following line verifies a successful return from the download and // display procedures. ResultsTextBox.Text += string.Format("\\r\\n\\r\\n#Group {0} is complete.\\r\\n", finishedGroup); } catch (Exception) { ResultsTextBox.Text += "\\r\\nDownloads failed."; } }