2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2016 The CefSharp Authors. All rights reserved.
|
2016-09-01 16:51:20 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
using System;
|
2019-06-02 20:34:44 +10:00
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Windows.Forms;
|
2018-09-17 00:46:21 +02:00
|
|
|
using CefSharp.Example.Handlers;
|
2016-09-01 16:51:20 +10:00
|
|
|
|
|
|
|
|
namespace CefSharp.WinForms.Example.Handlers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-05-15 21:27:56 +10:00
|
|
|
/// Minimal integration of CEF into existing message loop
|
2019-06-02 20:34:44 +10:00
|
|
|
/// The timer fires roughly <see cref="BrowserProcessHandler.SixtyTimesPerSecond"/>
|
2019-05-15 21:27:56 +10:00
|
|
|
/// times per second calling Cef.DoMessageLoopWork on the WinForms UI Thread.
|
2016-09-01 16:51:20 +10:00
|
|
|
/// See the following link for the CEF reference implementation.
|
|
|
|
|
/// https://bitbucket.org/chromiumembedded/cef/commits/1ff26aa02a656b3bc9f0712591c92849c5909e04?at=2785
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class WinFormsBrowserProcessHandler : BrowserProcessHandler
|
|
|
|
|
{
|
|
|
|
|
private Timer timer;
|
|
|
|
|
|
2019-06-02 20:34:44 +10:00
|
|
|
public WinFormsBrowserProcessHandler(IContainer components)
|
2016-09-01 16:51:20 +10:00
|
|
|
{
|
2019-06-02 20:34:44 +10:00
|
|
|
timer = new Timer(components) { Interval = SixtyTimesPerSecond };
|
2016-09-01 16:51:20 +10:00
|
|
|
timer.Start();
|
2019-06-02 20:34:44 +10:00
|
|
|
timer.Tick += TimerTick;
|
2016-09-01 16:51:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TimerTick(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-09-09 13:21:48 +10:00
|
|
|
//Basically execute Cef.DoMessageLoopWork 30 times per second
|
2019-06-02 20:34:44 +10:00
|
|
|
Cef.DoMessageLoopWork();
|
2016-09-01 16:51:20 +10:00
|
|
|
}
|
|
|
|
|
|
2021-05-11 20:24:48 +10:00
|
|
|
protected override void OnScheduleMessagePumpWork(long delay)
|
2016-09-01 16:51:20 +10:00
|
|
|
{
|
2019-05-15 21:27:56 +10:00
|
|
|
//NOOP - Only enabled when CefSettings.ExternalMessagePump
|
2016-09-01 16:51:20 +10:00
|
|
|
}
|
|
|
|
|
|
2021-05-11 20:24:48 +10:00
|
|
|
protected override void Dispose(bool disposing)
|
2016-09-01 16:51:20 +10:00
|
|
|
{
|
2021-05-11 20:24:48 +10:00
|
|
|
if(disposing)
|
2018-09-10 02:41:13 +02:00
|
|
|
{
|
2021-05-11 20:24:48 +10:00
|
|
|
if (timer != null)
|
|
|
|
|
{
|
|
|
|
|
timer.Stop();
|
|
|
|
|
timer.Dispose();
|
|
|
|
|
timer = null;
|
|
|
|
|
}
|
2016-09-01 16:51:20 +10:00
|
|
|
}
|
2021-05-11 20:24:48 +10:00
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
2016-09-01 16:51:20 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|