Last active
April 28, 2020 20:10
-
-
Save Vaccano/1b60d3f5b1b5f8d589f6ce7c00a60637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
static async void Main(string[] args) | |
{ | |
Func<Task> startupDone = async () => | |
{ | |
await Task.CompletedTask; | |
}; | |
var taskHere = startupDone.Invoke(); | |
var runTask = DoStuff(() => | |
{ | |
taskHere.Start(); | |
}); | |
// Here we wait for the task to finish. Or timeout. | |
var didStartup = taskHere.Wait(1000); | |
Console.WriteLine(!didStartup ? "Startup Timed Out" : "Startup Finished"); | |
await runTask; | |
Console.Read(); | |
} | |
public static async Task DoStuff(Action action) | |
{ | |
// Swap to 1000 to simulate starting up blocking | |
var blocking = 1; //1000; | |
await Task.Delay(500 + blocking); | |
action(); | |
// Do the rest of the stuff... | |
await Task.Delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment