Created
April 16, 2018 17:09
-
-
Save cgbeutler/5cd3a7a08f625524602f05474814a48f to your computer and use it in GitHub Desktop.
Programming Challenge: Comment in the async or sync version of each function so the output spells "EVIL" then try again to get it to spell "VILE"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace AsyncChallenge | |
{ | |
internal class Program | |
{ | |
// Comment in the async or sync version to try to get the program to print out: | |
// EVIL | |
// VILE | |
public static Task DoSomethingAsync() | |
{ | |
var task = new Task(() => Thread.Sleep(100)); | |
task.Start(); | |
Thread.Sleep(20); // Giving the thread time to start | |
return task; | |
} | |
// private static Task Four() | |
// { | |
// var task = DoSomethingAsync(); | |
// Console.Write("I"); | |
// return task; | |
// } | |
// ========== or ========== | |
// private static async Task Four() | |
// { | |
// await DoSomethingAsync(); | |
// Console.Write("I"); | |
// } | |
// private static Task Three() | |
// { | |
// var task = Four(); | |
// Console.Write("L"); | |
// return task; | |
// } | |
// ========== or ========== | |
// private static async Task Three() | |
// { | |
// await Four(); | |
// Console.Write("L"); | |
// } | |
// private static Task Two() | |
// { | |
// var task = Three(); | |
// Console.Write("E"); | |
// return task; | |
// } | |
// ========== or ========== | |
// private static async Task Two() | |
// { | |
// await Three(); | |
// Console.Write("E"); | |
// } | |
// private static Task One() | |
// { | |
// var task = Two(); | |
// Console.Write("V"); | |
// return task; | |
// } | |
// ========== or ========== | |
// private static async Task One() | |
// { | |
// await Two(); | |
// Console.Write("V"); | |
// } | |
private static void Main() | |
{ | |
ThreadPool.SetMinThreads(1, 0); | |
ThreadPool.SetMaxThreads(1, 0); | |
One().Wait(); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment