.NET Core Example - With simple Kestrel WebHost

CSharp · Console

/Program.cs

using System;
using System.Threading;
using System.Threading.Tasks;

public class Program
{
	public static async Task Main(string[] args)
	{
		var backgroundTask = Task.Run(() =>
		{
			Thread.Sleep(2000); //simulate some work
		}
		).ContinueWith(_ =>
		{
			Console.WriteLine("Running the continuation!");
		}, TaskContinuationOptions.NotOnRanToCompletion);
		await backgroundTask;
	}
}
;