Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SelfHost BrowserSubProcess

Alex Maitland edited this pageJul 26, 2025 ·6 revisions

CefSharp uses the samemultiprocess model asChromium. When you launch an application that embedsCefSharp then by default you will see multiple instances ofCefSharp.BrowserSubProcess.exe inTask Manager.

It is possible and in some casesrequired that youSelf Host theBrowserSubProcess.Self Host means that multiple instances ofyour application exe will be launched instead ofCefSharp.BrowserSubProcess.exe.

General

  • YouMUST set performDependencyCheck tofalse.
  • Add anApplication Manifest to your exe if you don't already have one, it's required for Windows 10 compatibility, GPU detection, HighDPI support and tooltips. You can review theCefSharp.BrowserSubProcess.exeapp.manifest for a working example.
  • For.Net 6+ when Publishing a Single file youmustSelf Host.
  • Better user experience when it comes to firewall permission prompts.
  • DPI Awareness will match that of your application.
  • 32bit executables should be madeLargeAddressAware. See alsohttps://github.com/cefsharp/CefSharp/wiki/General-Usage#win32-out-of-memory
  • For64bit executables increasing theStack Size to 8mb to matchChromium is recommended.
  • If running onTerminal Server then make your applicationTSAware

WinForms

Self Hosting usingWinForms is very easy, forx64/x86 build yourProgram.cs would look something like:

publicstaticclassProgram{[STAThread]publicstaticintMain(string[]args){varexitCode=CefSharp.BrowserSubprocess.SelfHost.Main(args);if(exitCode>=0){returnexitCode;}varsettings=newCefSettings(){//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist dataCachePath=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 falseCef.Initialize(settings,performDependencyCheck:false,browserProcessHandler:null);varbrowser=newBrowserForm();Application.Run(browser);return0;}}

WPF

ForWPF there are a few steps required as the compiler generates theMain method for you. You need to:

  • Create your own custom entry point (typically adding aProgram.cs file with astatic Main method) that callsApplication.Run
  • Change the<StartupObject/> to use your own main method, (Right click Properties on your project, Startup Object is a dropdown or edit your proj file manually).

Yourproj file should look something like:

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

Forx64/x64 build yourProgram.cs would look something like:

namespaceMyApp{publicstaticclassProgram{[STAThread]publicstaticintMain(string[]args){varexitCode=CefSharp.BrowserSubprocess.SelfHost.Main(args);if(exitCode>=0){returnexitCode;}varsettings=newCefSettings(){//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist dataCachePath=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"CefSharp\\Cache"),BrowserSubprocessPath=System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName};//IMPORTANT: MUST set performDependencyCheck falseCef.Initialize(settings,performDependencyCheck:false,browserProcessHandler:null);varapp=newApp();app.InitializeComponent();returnapp.Run();}}}

Anyone with a GitHub account can edit this wiki, contributions are encouraged and welcomed.

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp