Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace MyApp
{
internal static class Program
{
public static void Main(string[] args)
{
var scheduler = new MyTaskScheduler();
var context = new MySynchronizationContext(scheduler);
context.Post(Run, null);
Thread.Sleep(3000);
}
private static void Run(object state)
{
RunAsync(); // no await here, intentional.
}
private static async Task RunAsync()
{
Logger.WriteLine("Before InternalRunAsync"); //
Подробнее здесь: [url]https://stackoverflow.com/questions/55320330/c-sharp-why-my-taskscheduler-is-replaced-by-the-default-one-after-certain-awai[/url]