mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +00:00
7af206edbb
* Update reference from https://bitbucket.org/chromiumembedded/cef to https://github.com/chromiumembedded/cef * Apply suggestion from @campersau
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
// Copyright © 2016 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.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using CefSharp.Example.Handlers;
|
|
|
|
namespace CefSharp.WinForms.Example.Handlers
|
|
{
|
|
/// <summary>
|
|
/// Minimal integration of CEF into existing message loop
|
|
/// The timer fires roughly <see cref="BrowserProcessHandler.SixtyTimesPerSecond"/>
|
|
/// times per second calling Cef.DoMessageLoopWork on the WinForms UI Thread.
|
|
/// See the following link for the CEF reference implementation.
|
|
/// https://github.com/chromiumembedded/cef/commit/1ff26aa02a656b3bc9f0712591c92849c5909e04
|
|
/// </summary>
|
|
public class WinFormsBrowserProcessHandler : BrowserProcessHandler
|
|
{
|
|
private Timer timer;
|
|
|
|
public WinFormsBrowserProcessHandler(IContainer components)
|
|
{
|
|
timer = new Timer(components) { Interval = SixtyTimesPerSecond };
|
|
timer.Start();
|
|
timer.Tick += TimerTick;
|
|
}
|
|
|
|
private void TimerTick(object sender, EventArgs e)
|
|
{
|
|
//Basically execute Cef.DoMessageLoopWork 30 times per second
|
|
Cef.DoMessageLoopWork();
|
|
}
|
|
|
|
protected override void OnScheduleMessagePumpWork(long delay)
|
|
{
|
|
//NOOP - Only enabled when CefSettings.ExternalMessagePump
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if(disposing)
|
|
{
|
|
if (timer != null)
|
|
{
|
|
timer.Stop();
|
|
timer.Dispose();
|
|
timer = null;
|
|
}
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|