Page 2 of 3

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 7:38 pm
by nhatnm
amaitland wrote:Does SharpBrowser use a RequestContext to isolate it's ChromiumWebBrowser instances?
I've you tried removing all the command line args/settings except CachePath?

Try FindAll, I didn't see any RequestContext and CefCommandLineArgs in . I'm silly, didn't think must find this before ask. So, what magic it used?
About your link, I have read and pratice many times. With my understand, it'll help me clear the browser after used RequestContext, then can reload BrowserSettings and CefSettings but not CefCommandLineArgs. I think it's good for use multi-profiles for multi-tabs, right? And does it prossible re-link to other render process?
And I'm also read this your post , I don't know javascript it's hard for me understand. But does it useful for this?

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 7:48 pm
by amaitland
amaitland wrote:If you have two tabs with one tab active then potentially what you are seeing is Potentially what you are seeing is https://github.com/cefsharp/CefSharp/issues/2922

It's possible the difference between your application and SharpBrowser is how the tabs behave, they appear to be using some form of custom BrowserTabStrip


This is my best guess as to what's going on. Your inactive tab is still running in the background. Manually call Hide()/Show() when the tab changes to ensure the background ChromiumWebBrowser controls are hidden.

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 7:49 pm
by nhatnm
Yes, thanks your idea, I'll try Control.VisibleChanged

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 8:13 pm
by amaitland
That's unlikely to work, it's not called when a Control within a TabControl becomes hidden (Visible = false).

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 8:34 pm
by amaitland
You may need to use a custom implementation like ChromiumWebBrowser like the following to ensure the underlying CefBrowser size is set to 0,0 when hidden to ensure the resource usage is decreased.

Code: Select all
public class ChromiumWebBrowserEx : ChromiumWebBrowser
{
   public ChromiumWebBrowserEx(string address) : base(address)
   {

   }

   protected override void OnVisibleChanged(EventArgs e)
   {
      if(Visible)
      {
         ResizeBrowser(Width, Height);
      }
      else
      {
         ResizeBrowser(0, 0);
      }

      base.OnVisibleChanged(e);
   }
}

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 8:43 pm
by nhatnm
here's my result: yahoo, it' worked
3.png
3.png (283.78 KiB) Viewed 4761 times


my code:
Code: Select all
tab.VisibleChanged += new EventHandler(this.TabVisibleChanged);
private void TabVisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                //MessageBox.Show("raised");
                tabControl.SelectedTab.Show();
            }
            else tabControl.SelectedTab.Hide();
        }

But I have little question.
- With MessageBox.Show for test, I see it showed 2 times, mean all tab will fire 2 times for every my touch to them. Something incorrect in my do?
- Why this this can make share render process, I can't understand

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 8:44 pm
by nhatnm
amaitland wrote:You may need to use a custom implementation like ChromiumWebBrowser like the following to ensure the underlying CefBrowser size is set to 0,0 when hidden to ensure the resource usage is decreased.

Code: Select all
public class ChromiumWebBrowserEx : ChromiumWebBrowser
{
   public ChromiumWebBrowserEx(string address) : base(address)
   {

   }

   protected override void OnVisibleChanged(EventArgs e)
   {
      if(Visible)
      {
         ResizeBrowser(Width, Height);
      }
      else
      {
         ResizeBrowser(0, 0);
      }

      base.OnVisibleChanged(e);
   }
}

oops, I'll try your code

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 8:52 pm
by amaitland
If your resource usage decreased then you likely don't need the code I provided.

Code: Select all
With MessageBox.Show for test, I see it showed 2 times, mean all tab will fire 2 times for every my touch to them. Something incorrect in my do?


You are checking the Visible property for the class you are in, not a specific Tab instance. Your code is likely incorrect.

Re: need help winform RequestContext/share render process

PostPosted: Fri Jun 04, 2021 9:47 pm
by nhatnm
Sorry for my silly question. Could you guide me how to use "ResizeBrowser" in your way?

Re: need help winform RequestContext/share render process

PostPosted: Sat Jun 05, 2021 2:27 am
by amaitland
ResizeBrowser is a protected method and cannot be called directly.