public static async Task AsyncAwaitTaskPlayerExample() { var player = new AwaitTaskPlayer(); await player.Load("folder"); await player.Play(); }
//Текущий поток не блокируется public static void AwaitTaskPlayerExample2() { var player = new AwaitTaskPlayer(); var task = player.Load("folder"); task.ContinueWith((t) => player.Play()); }
//Текущий поток блокируется public static void AwaitTaskPlayerExample() { var player = new AwaitTaskPlayer(); var task = player.Load("folder"); task.Wait(); player.Play(); }
public static async Task AsyncAwaitTaskPlayerExample() { var c1 = SynchronizationContext.Current; SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); var player = new AwaitTaskPlayer(); await player.Load("folder"); await player.Play(); }
//Текущий поток не блокируется public static void AwaitTaskPlayerExample2() { var c1 = SynchronizationContext.Current; SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); var player = new AwaitTaskPlayer(); var task = player.Load("folder"); task.ContinueWith((t) => { var c2 = SynchronizationContext.Current; player.Play(); }); }