P
P
PickGG2019-11-24 15:02:23
C++ / C#
PickGG, 2019-11-24 15:02:23

What is the problem with async/await?

public async void StartAsync()
        {
            Console.WriteLine(Thread.CurrentThread.ManagedThreadId); // 1
            var browser = await GetBrowserAsync(false);
        }
        private static Browser browser;
        private async Task<Browser> GetBrowserAsync(bool headless)
        {
            if (browser == null)
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId); // 1
                var options = new LaunchOptions { Headless = headless };
                await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); // Скачиваем Chrome в директорию с exe
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId); // 1
                browser = await Puppeteer.LaunchAsync(options); // Запускаем браузер
            }
            return await Task.FromResult(browser);
        }

The error System.IO.FileNotFoundException is thrown: "Failed to launch chrome! path to executable does not exist". That is, the line browser = await Puppeteer.LaunchAsync(options); executed immediately after the line await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); and the browser just does not have time to download

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question