예제 #1
0
파일: Program.cs 프로젝트: wuzlai/CefNet
        private static async void OnScheduleMessagePumpWork(long delayMs)
        {
            await Task.Delay((int)delayMs);

            UIContext.Post(_ => CefApi.DoMessageLoopWork(), null);
        }
예제 #2
0
파일: Program.cs 프로젝트: wuzlai/CefNet
        static void Main(string[] args)
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            string cefPath             = Path.Combine(Path.GetDirectoryName(GetProjectPath()), "cef");
            bool   externalMessagePump = args.Contains("--external-message-pump");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += Application_ThreadException;

            var settings = new CefSettings();

            settings.MultiThreadedMessageLoop = !externalMessagePump;
            settings.ExternalMessagePump      = externalMessagePump;
            settings.NoSandbox = true;
            settings.WindowlessRenderingEnabled = true;
            settings.LocalesDirPath             = Path.Combine(cefPath, "Resources", "locales");
            settings.ResourcesDirPath           = Path.Combine(cefPath, "Resources");
            settings.LogSeverity                = CefLogSeverity.Warning;
            settings.IgnoreCertificateErrors    = true;
            settings.UncaughtExceptionStackSize = 8;

            var app = new CefAppImpl();

            app.ScheduleMessagePumpWorkCallback = OnScheduleMessagePumpWork;
            app.CefProcessMessageReceived      += ScriptableObjectTests.HandleScriptableObjectTestMessage;
            try
            {
                UIContext = new WindowsFormsSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(UIContext);

                app.Initialize(Path.Combine(cefPath, "Release"), settings);

                if (externalMessagePump)
                {
                    messagePump = new System.Threading.Timer(_ => UIContext.Post(_ => CefApi.DoMessageLoopWork(), null), null, messagePumpDelay, messagePumpDelay);
                }

                Application.Run(new MainForm());
            }
            finally
            {
                messagePump?.Dispose();
                app.Shutdown();
                app.Dispose();
            }
        }