Files
cefsharp/CefSharp.WinForms.Example/Program.cs
T
Konstantin Preißer 5e89f71a44 Add new projects targeting .NET Core 3.1 (#3181)
* Add .NET Core 3.1 projects for CefSharp, CefSharp.Core, CefSharp.BrowserSubprocess.Core, CefSharp.WinForms, CefSharp.Wpf, CefSharp.OffScreen.

Contributes to CefSharp#2796

* - Remove dependencies to "opengl32.lib" and "glu32.lib" which aren't available for ARM64 and don't seem to be needed.
- Clean up project files.

* Switch project CefSharp.netcore.csproj to AnyCPU as it doesn't require different builds for each platform.

* Remove WindowsTargetPlatformVersion property as that is declared in CefSharp.props.

* Use "bin.netcore" and "obj.netcore" as [intermediate] output path for the .NET Core projects, to allow side-by-side builds with the .NET Framework projects.

* Output documentation files.

* Add CefSharp.Example.netcore and CefSharp.WinForms.Example.netcore.

* Follow-up: Remove properties from the example projects that are also not used in the corresponding .NET Framework projects.
2020-07-23 15:21:14 +10:00

118 lines
4.4 KiB
C#

// Copyright © 2010 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp.Example;
using CefSharp.Example.Handlers;
using CefSharp.WinForms.Example.Handlers;
using CefSharp.WinForms.Example.Minimal;
namespace CefSharp.WinForms.Example
{
public class Program
{
[STAThread]
public static int Main(string[] args)
{
const bool simpleSubProcess = false;
Cef.EnableHighDPISupport();
//NOTE: Using a simple sub processes uses your existing application executable to spawn instances of the sub process.
//Features like JSB, EvaluateScriptAsync, custom schemes require the CefSharp.BrowserSubprocess to function
if (simpleSubProcess)
{
var exitCode = Cef.ExecuteProcess();
if (exitCode >= 0)
{
return exitCode;
}
#if DEBUG
if (!System.Diagnostics.Debugger.IsAttached)
{
MessageBox.Show("When running this Example outside of Visual Studio " +
"please make sure you compile in `Release` mode.", "Warning");
}
#endif
var settings = new CefSettings();
settings.BrowserSubprocessPath = System.IO.Path.GetFullPath("CefSharp.WinForms.Example.exe");
Cef.Initialize(settings);
var browser = new SimpleBrowserForm(true);
Application.Run(browser);
}
else
{
#if NETCOREAPP
//We are using our current exe as the BrowserSubProcess
//Multiple instances will be spawned to handle all the
//Chromium proceses, render, gpu, network, plugin, etc.
var subProcessExe = new CefSharp.BrowserSubprocess.BrowserSubprocessExecutable();
var result = subProcessExe.Main(args);
if (result > 0)
{
return result;
}
#endif
#if DEBUG
if (!System.Diagnostics.Debugger.IsAttached)
{
MessageBox.Show("When running this Example outside of Visual Studio " +
"please make sure you compile in `Release` mode.", "Warning");
}
#endif
//When multiThreadedMessageLoop = true then externalMessagePump must be set to false
// To enable externalMessagePump set multiThreadedMessageLoop = false and externalMessagePump = true
const bool multiThreadedMessageLoop = true;
const bool externalMessagePump = false;
var browser = new BrowserForm(multiThreadedMessageLoop);
//var browser = new SimpleBrowserForm(multiThreadedMessageLoop);
//var browser = new TabulationDemoForm();
IBrowserProcessHandler browserProcessHandler;
if (multiThreadedMessageLoop)
{
browserProcessHandler = new BrowserProcessHandler();
}
else
{
if (externalMessagePump)
{
//Get the current taskScheduler (must be called after the form is created)
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
browserProcessHandler = new ScheduleMessagePumpBrowserProcessHandler(scheduler);
}
else
{
//We'll add out WinForms timer to the components container so it's Diposed
browserProcessHandler = new WinFormsBrowserProcessHandler(browser.Components);
}
}
var settings = new CefSettings();
settings.MultiThreadedMessageLoop = multiThreadedMessageLoop;
settings.ExternalMessagePump = externalMessagePump;
CefExample.Init(settings, browserProcessHandler: browserProcessHandler);
//Application.Run(new MultiFormAppContext(multiThreadedMessageLoop));
Application.Run(browser);
}
return 0;
}
}
}