Skip to content

Instantly share code, notes, and snippets.

@Vaccano
Last active April 28, 2020 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vaccano/1b60d3f5b1b5f8d589f6ce7c00a60637 to your computer and use it in GitHub Desktop.
Save Vaccano/1b60d3f5b1b5f8d589f6ce7c00a60637 to your computer and use it in GitHub Desktop.
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