using System.Threading.Tasks;
namespace LISTING_1_13_Task_Factory
public static void Main(string[] args)
CancellationTokenSource cts = new CancellationTokenSource();
TaskFactory factory = new TaskFactory(
TaskCreationOptions.PreferFairness,
TaskContinuationOptions.ExecuteSynchronously,
Task t2 = factory.StartNew(() => DoWork());
Console.WriteLine("Press enter to dispose of the task");
Console.WriteLine("Disposing of the task");
Console.WriteLine("Doing work..");
for (int i = 0; i < 5000; i++)
Console.WriteLine("Result: " + total);