namespace Cef3
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Cef3.Interop;
///
/// Class that asynchronously executes tasks on the associated thread. It is safe
/// to call the methods of this class on any thread.
/// CEF maintains multiple internal threads that are used for handling different
/// types of tasks in different processes. The cef_thread_id_t definitions in
/// cef_types.h list the common CEF threads. Task runners are also available for
/// other CEF threads as appropriate (for example, V8 WebWorker threads).
///
public sealed unsafe partial class CefTaskRunner
{
///
/// Returns the task runner for the current thread. Only CEF threads will have
/// task runners. An empty reference will be returned if this method is called
/// on an invalid thread.
///
public static CefTaskRunner GetForCurrentThread()
{
return CefTaskRunner.FromNativeOrNull(cef_task_runner_t.get_for_current_thread());
}
///
/// Returns the task runner for the specified CEF thread.
///
public static CefTaskRunner GetForThread(CefThreadId threadId)
{
return CefTaskRunner.FromNativeOrNull(cef_task_runner_t.get_for_thread(threadId));
}
///
/// Returns true if this object is pointing to the same task runner as |that|
/// object.
///
public bool IsSame(CefTaskRunner that)
{
return cef_task_runner_t.is_same(_self, that.ToNative()) != 0;
}
///
/// Returns true if this task runner belongs to the current thread.
///
public bool BelongsToCurrentThread
{
get { return cef_task_runner_t.belongs_to_current_thread(_self) != 0; }
}
///
/// Returns true if this task runner is for the specified CEF thread.
///
public bool BelongsToThread(CefThreadId threadId)
{
return cef_task_runner_t.belongs_to_thread(_self, threadId) != 0;
}
///
/// Post a task for execution on the thread associated with this task runner.
/// Execution will occur asynchronously.
///
public bool PostTask(CefTask task)
{
return cef_task_runner_t.post_task(_self, task.ToNative()) != 0;
}
///
/// Post a task for delayed execution on the thread associated with this task
/// runner. Execution will occur asynchronously. Delayed tasks are not
/// supported on V8 WebWorker threads and will be executed without the
/// specified delay.
///
public bool PostDelayedTask(CefTask task, long delay)
{
return cef_task_runner_t.post_delayed_task(_self, task.ToNative(), delay) != 0;
}
}
}