async/await broken by Expression Encoder Screen Capture

99 views Asked by At

I am trying to invoke Expression Encoder ScreenCapture within a console app. I can record the screen but I am finding that it is breaking async/await.

In the code below, "await Task.Delay()" will not return unless "new ScreenCaptureJob()" is commented out. I guess that the screen capture library may be creating a GUI event queue or something in the background that might be interfering with async-await.

Note that the real application is doing real async/await work so it cannot be replaced with a Thread.Sleep.

Any idea how to fix this?

using Microsoft.Expression.Encoder.ScreenCapture;
using Microsoft.Extensions.CommandLineUtils;
using System;
using System.IO;
using System.IO.Pipes;
using System.Threading;
using System.Threading.Tasks;

namespace ScreenRecorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var app = new CommandLineApplication();

            app.OnExecute(async () =>
            {
                var scj = new ScreenCaptureJob();

                Console.WriteLine("Being wait");

                await Task.Delay(50);

                Console.WriteLine("End wait");

                return 0;
            });

            app.Execute(args);
        }
    }
}
0

There are 0 answers