Added 3 new Listings via their respective code in manuscript
ADD
src/Chapter20/Listing20.13.SynchronousHighLatencyInvocationInWPF.cs
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_12
+{
+ using System;
+ using System.Threading;
+ using System.Threading.Tasks;
+
+ public class Program
+ {
+ public static void Main()
+ {
+ DisplayStatus("Before");
+ Task taskA =
+ Task.Run(() =>
+ DisplayStatus("Starting..."))
+ .ContinueWith(antecedent =>
+ DisplayStatus("Continuing A..."));
+ Task taskB = taskA.ContinueWith(antecedent =>
+ DisplayStatus("Continuing B..."));
+ Task taskC = taskA.ContinueWith(antecedent =>
+ DisplayStatus("Continuing C..."));
+ Task.WaitAll(taskB, taskC);
+ DisplayStatus("Finished!");
+ }
+
+ private static void DisplayStatus(string message)
+ {
+ string text =
+ $@"{ Thread.CurrentThread.ManagedThreadId
+ }: { message }";
+
+
+ Console.WriteLine(text);
+ }
+ }
+}
+
+
+
+
+

ADD
src/Chapter20/Listing20.14.SynchronousHighLatencyInvocationInWPFUsingAwait.cs
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_12
+{
+ using System;
+ using System.Threading;
+ using System.Threading.Tasks;
+
+ public class Program
+ {
+ public static void Main()
+ {
+ DisplayStatus("Before");
+ Task taskA =
+ Task.Run(() =>
+ DisplayStatus("Starting..."))
+ .ContinueWith(antecedent =>
+ DisplayStatus("Continuing A..."));
+ Task taskB = taskA.ContinueWith(antecedent =>
+ DisplayStatus("Continuing B..."));
+ Task taskC = taskA.ContinueWith(antecedent =>
+ DisplayStatus("Continuing C..."));
+ Task.WaitAll(taskB, taskC);
+ DisplayStatus("Finished!");
+ }
+
+ private static void DisplayStatus(string message)
+ {
+ string text =
+ $@"{ Thread.CurrentThread.ManagedThreadId
+ }: { message }";
+
+
+ Console.WriteLine(text);
+ }
+ }
+}
+
+
+
+
+

ADD
src/Chapter20/Listing20.15.IteratingOverAwaitOperation.cs
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_15
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Net.NetworkInformation;
+ using System.Threading;
+ using System.Threading.Tasks;
+
+ public class Program
+ {
+ async private void PingButton_Click(
+ object sender, RoutedEventArgs e)
+ {
+ List<string> urls = new List<string>()
+ {
+ "www.habitat-spokane.org",
+ "www.partnersintl.org",
+ "www.iassist.org",
+ "www.fh.org",
+ "www.worldvision.org"
+ };
+ IPStatus status;
+
+ Func<string, Task<IPStatus>> func =
+ async (localUrl) =>
+ {
+ Ping ping = new Ping();
+ PingReply pingReply =
+ await ping.SendPingAsync(localUrl);
+ return pingReply.Status;
+ };
+
+ StatusLabel.Content = "Pinging";
+
+ foreach (string url in urls)
+ {
+ status = await func(url);
+ StatusLabel.Text =
+ $@"{ url }: { status.ToString() } ({
+ Thread.CurrentThread.ManagedThreadId })";
+ }
+ }
+
+ }
+}
+
+
+
+
+

Added 3 new Listings via their respective code in manuscript