A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/cefsharp/CefSharp/wiki/SelfHost-BrowserSubProcess below:

SelfHost BrowserSubProcess · cefsharp/CefSharp Wiki · GitHub

CefSharp uses the same multiprocess model as Chromium. When you launch an application that embeds CefSharp then by default you will see multiple instances of CefSharp.BrowserSubProcess.exe in Task Manager.

It is possible and in some cases required that you Self Host the BrowserSubProcess. Self Host means that multiple instances of your application exe will be launched instead of CefSharp.BrowserSubProcess.exe.

Self Hosting using WinForms is very easy, for x64/x86 build your Program.cs would look something like:

public static class Program
{
	[STAThread]
	public static int Main(string[] args)
	{
		var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args);

		if (exitCode >= 0)
		{
			return exitCode;
		}

		var settings = new CefSettings()
		{
			//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
			CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
			BrowserSubprocessPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
		};

		//Perform dependency check to make sure all relevant resources are in our output directory.
		//IMPORTANT: MUST set performDependencyCheck false
		Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);

		var browser = new BrowserForm();
		Application.Run(browser);

		return 0;
	}
}

For WPF there are a few steps required as the compiler generates the Main method for you. You need to:

Your proj file should look something like:

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <StartupObject>MyApp.Program</StartupObject>
</PropertyGroup> 

For x64/x64 build your Program.cs would look something like:

namespace MyApp
{
	public static class Program
	{
		[STAThread]
		public static int Main(string[] args)
		{
			var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args);

			if (exitCode >= 0)
			{
				return exitCode;
			}

			var settings = new CefSettings()
			{
				//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
				CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
				BrowserSubprocessPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
			};

			//IMPORTANT: MUST set performDependencyCheck false
			Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);

			var app = new App();
			app.InitializeComponent();
			return app.Run();
		}
	}
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4