question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page.Dispose() never completes

See original GitHub issue

Using 0.3.2, if you try to dispose of a Page instance, it awaits forever. Try this, the last Console.WriteLine() call is never reached because it all hangs when the inner using statement calls Dispose on the page instance.

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using PuppeteerSharp;

namespace PuppeteerSharpPdfDemo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            MainAsync().GetAwaiter().GetResult();
        }

        public static async Task MainAsync()
        {
            var options = new LaunchOptions
            {
                Headless = true
            };

            Console.WriteLine("Downloading chromium");
            await Downloader.CreateDefault().DownloadRevisionAsync(Downloader.DefaultRevision);

            Console.WriteLine("Navigating google");
            using (var browser = await Puppeteer.LaunchAsync(options, Downloader.DefaultRevision))
            using (var page = await browser.NewPageAsync())
            {
                await page.GoToAsync("http://www.google.com");

                Console.WriteLine("Generating PDF");
                await page.PdfAsync(Path.Combine(Directory.GetCurrentDirectory(), "google.pdf"));

                Console.WriteLine("Export completed");
                //Console.ReadLine();
            }
            Console.WriteLine("The End"); // this line never reached :(
        }
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kemmiscommented, Apr 7, 2018

Okay that works!

0reactions
kblokcommented, Apr 7, 2018

It’s something we need to work on, of course. I’m glad you got it running!

(don’t close this issue)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page.Dispose() never completes · Issue #122
Using 0.3.2, if you try to dispose of a Page instance, it awaits forever. Try this, the last Console.WriteLine() call is never reached ......
Read more >
What happens to Tasks that are never completed? Are they ...
However, let's say SetResult(..) is never called, and someClassInstance stops being referenced and is garbage collected. Does this create a ...
Read more >
Implement a DisposeAsync method
The DisposeAsync() returns a ValueTask that represents the asynchronous disposal operation. It's typical when implementing the IAsyncDisposable ...
Read more >
autoDispose
autoDispose. A common use case is to destroy the state of a provider when it is no-longer used. There are multiple reasons for...
Read more >
Shared Context between Tests
For context cleanup, add the IDisposable interface to your test class, and put the cleanup code in the Dispose() method. Here is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found