title: Why is the using variable disposing itself before leaving the method?
body: <pre><code>using PuppeteerSharp;
  using System;
  using System.Threading.Tasks;
  
  namespace Video_Handler
  {
      public class VideoHost
      {
          private static bool Is_HTTPS_URL(string url)
          {
              Uri uriResult;
  
              bool result = Uri.TryCreate(url, UriKind.Absolute, out uriResult) &amp;&amp; (uriResult.Scheme == Uri.UriSchemeHttps);
              return result;
          }
  
          #region BrowserCreationCode
          private static async Task FectchBrowserIfItIsNotThere()
          {
              var browserFetcher = new BrowserFetcher();
              await browserFetcher.DownloadAsync();
          }
          internal static async Task&lt;Page&gt; GetPageAsync(string url, bool isPageInvisible = true, Action&lt;Page&gt; action)
          {
              if(!Is_HTTPS_URL(url))
              {
                  throw new ArgumentException($&quot;The url | {url} | is not an https url.&quot;);
              }
              await FectchBrowserIfItIsNotThere();
              await using var browser = await Puppeteer.LaunchAsync(
                  new LaunchOptions { Headless = isPageInvisible });
              await using var page = await browser.NewPageAsync();
              await page.GoToAsync(url);
              action(page);
              return page;
          }
      }
  }
  </code></pre>
  <pre><code>//Boiler Plate code
  async static void Main()
  {
    Action&lt;Page&gt; action = (page) =&gt; Foo(page);
    await GetPageAsync(&quot;https://google.com&quot;, false , action);
  }
  public static async Task Foo(Page p){ 
     await p.EvaluateExpression(&quot;//fill google search bar&quot;); //first line
     await p.EvaluateExpression(&quot;//click search button&quot;);  //second line
     await p.WaitForNavigationAsync(); //third line
     await p.EvaluateExpression(&quot;alert(&quot;hi&quot;)&quot;); //fourth line
  }
  </code></pre>
  <p>I am having an issue where when I send the <strong>page</strong> variable to the action which takes in a page variable it causes the page or browser variable to be disposed. From what I understand about using, this should only happen if I leave the function's parenthesis. I have read Microsoft's documentation on        <em><strong><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement" rel="nofollow noreferrer">using</a></strong></em> and I can't find anything that tells me that the page variable disposes itself upon going to another function within the function the using variable is in.</p>
  <p>Also, occasionally the code will be able to evaluate some of the function's expressions but it usually fails by the third. However, if I debug and run step by step, it always fails on the first line. This is what led me to believe it is a disposal issue.</p>
  <p>To anyone wondering why I have not just removed the using from <strong>browser</strong> and <strong>page</strong> variables and dispose of them myself, I have two reasons. One, I don't have experience with disposing unmanaged code and when I tried to add the dispose to the finalizer/destructor it doesn't work and Secondly, I don't want to write code to do what the language already does for me.</p>