Ejemplo n.º 1
0
 public unsafe int BelongsToThread(CefThreadId threadId)
 {
     fixed(cef_task_runner_t *self = &this)
     {
         return(((delegate * unmanaged[Stdcall] < cef_task_runner_t *, CefThreadId, int >)belongs_to_thread)(self, threadId));
     }
 }
 public static Task RunAsync(CefThreadId threadId, Action action)
 {
     if (CefRuntime.CurrentlyOn(threadId))
     {
         action();
         return(TaskHelpers.Completed());
     }
     else
     {
         var tcs = new TaskCompletionSource <FakeVoid>();
         StartNew(threadId, () =>
         {
             try
             {
                 action();
                 tcs.SetResultAsync(default(FakeVoid));
             }
             catch (Exception e)
             {
                 tcs.SetExceptionAsync(e);
             }
         });
         return(tcs.Task);
     }
 }
Ejemplo n.º 3
0
 private void OnExecute(IntPtr self, CefThreadId threadid)
 {
     if (_action != null) {
         _action();
     }
     OnExecuted(EventArgs.Empty);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Post a task for delayed execution on the specified thread. This function may
        /// be called on any thread. It is an error to request a thread from the wrong
        /// process.
        /// </summary>
        public static bool PostTask(CefThreadId threadId, CefTask task, long delay)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            return(libcef.post_delayed_task(threadId, task.ToNative(), delay) != 0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Post a task for delayed execution on the specified thread.
        /// This function may be called on any thread.
        /// </summary>
        public static void PostTask(CefThreadId threadId, CefTask task, long delayMs)
        {
            var result = NativeMethods.cef_post_delayed_task((cef_thread_id_t)threadId, task.GetNativePointerAndAddRef(), delayMs) != 0;

            if (!result)
            {
                ThrowPostTaskError();
            }
        }
Ejemplo n.º 6
0
        public static TaskScheduler GetTaskScheduler(CefThreadId threadId)
        {
            CefTaskScheduler result;

            if (!TaskSchedulers.TryGetValue(threadId, out result))
            {
                result = new CefTaskScheduler(threadId);
                TaskSchedulers.Add(threadId, result);
            }
            return(result);
        }
 protected override void Execute(CefThreadId threadId)
 {
     try
     {
         this.d(this.state);
     }
     finally
     {
         if (this.waitHandle != null)
         {
             this.waitHandle.Set();
         }
     }
 }
Ejemplo n.º 8
0
 protected override void Execute(CefThreadId threadId)
 {
     try
     {
         this.d(this.state);
     }
     finally
     {
         if (this.waitHandle != null)
         {
             this.waitHandle.Set();
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Executes the task on the selected CEF thread.
        /// </summary>
        /// <param name="threadId">The thread identifier.</param>
        /// <param name="action">The action.</param>
        /// <exception cref="System.ArgumentNullException">action</exception>
        public static void ExecuteTask(CefThreadId threadId, Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            if (!CefRuntime.CurrentlyOn(threadId))
            {
                CefRuntime.PostTask(threadId, new ActionTask(action));
            }
            else
            {
                action();
            }
        }
Ejemplo n.º 10
0
        public static int belongs_to_thread(cef_task_runner_t *self, CefThreadId threadId)
        {
            belongs_to_thread_delegate d;
            var p = self->_belongs_to_thread;

            if (p == _p5)
            {
                d = _d5;
            }
            else
            {
                d = (belongs_to_thread_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(belongs_to_thread_delegate));
                if (_p5 == IntPtr.Zero)
                {
                    _d5 = d; _p5 = p;
                }
            }
            return(d(self, threadId));
        }
        /// <summary>
        /// Returns the <see cref="CefNetSynchronizationContextAwaiter"/> for the specified CEF thread.
        /// </summary>
        /// <param name="threadId">The CEF thread identifier.</param>
        /// <returns>The <see cref="CefNetSynchronizationContextAwaiter"/> for the CEF thread.</returns>
        public static CefNetSynchronizationContextAwaiter GetForThread(CefThreadId threadId)
        {
            CefNetSynchronizationContextAwaiter instance;

            _SyncRoot.EnterReadLock();
            try
            {
                _Awaiters.TryGetValue(threadId, out instance);
            }
            finally
            {
                _SyncRoot.ExitReadLock();
            }
            if (instance != null)
            {
                return(instance);
            }

            // These awaiters should have been added in the static constructor.
            if (threadId == CefThreadId.Renderer || threadId == CefThreadId.UI)
            {
                throw new ArgumentOutOfRangeException(nameof(threadId));
            }

            _SyncRoot.EnterWriteLock();
            try
            {
                if (!_Awaiters.TryGetValue(threadId, out instance))
                {
                    instance = new CefNetSynchronizationContextAwaiter(threadId);
                    _Awaiters.Add(threadId, instance);
                }
            }
            finally
            {
                _SyncRoot.ExitWriteLock();
            }
            return(instance);
        }
 public static void StartNew(CefThreadId threadId, Action action)
 {
     CefRuntime.PostTask(threadId, new CefActionTask(action));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns true if this task runner is for the specified CEF thread.
 /// </summary>
 public bool BelongsToThread(CefThreadId threadId)
 {
     return cef_task_runner_t.belongs_to_thread(_self, threadId) != 0;
 }
Ejemplo n.º 14
0
 public static extern int CefPostDelayedTask(CefThreadId threadid, IntPtr task, long delayMs);
Ejemplo n.º 15
0
 /// <summary>
 /// Causes the calling thread to yield execution to the specified CEF thread.
 /// </summary>
 /// <param name="threadId">The CEF thread identifier to switch to.</param>
 /// <returns>
 /// An object that is notified when the switch to the CEF thread operation is finished.
 /// </returns>
 protected CefNetSynchronizationContextAwaiter SwitchToCefThread(CefThreadId threadId)
 {
     return(CefNetSynchronizationContextAwaiter.GetForThread(threadId));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// CEF maintains multiple internal threads that are used for handling different
 /// types of tasks in different processes. See the cef_thread_id_t definitions in
 /// cef_types.h for more information. This function will return true if called on
 /// the specified thread. It is an error to request a thread from the wrong
 /// process.
 /// </summary>
 public static bool CurrentlyOn(CefThreadId threadId)
 {
     return libcef.currently_on(threadId) != 0;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// The post task.
 /// </summary>
 /// <param name="threadId">
 /// The thread id.
 /// </param>
 /// <param name="action">
 /// The action.
 /// </param>
 /// <param name="flag">
 /// The flag.
 /// </param>
 private void PostTask(CefThreadId threadId, Action <bool> action, bool flag)
 {
     CefRuntime.PostTask(threadId, new ActionTask4(action, flag));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Post a task for delayed execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public void Post(CefThreadId threadId, long delayMs)
 {
     Cef.PostTask(threadId, this, delayMs);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Post a task for execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public void Post(CefThreadId threadId)
 {
     Cef.PostTask(threadId, this);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Post a task for delayed execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public static void Post(CefThreadId threadId, Action action, long delayMs)
 {
     Cef.PostTask(threadId, new CefActionTask(action), delayMs);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Post a task for execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public static void Post(CefThreadId threadId, Action action)
 {
     Cef.PostTask(threadId, new CefActionTask(action));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Post a task for delayed execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public static void Post(CefThreadId threadId, CefTask task, long delayMs)
 {
     Cef.PostTask(threadId, task, delayMs);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Post a task for execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public static void Post(CefThreadId threadId, CefTask task)
 {
     Cef.PostTask(threadId, task);
 }
 private CefNetSynchronizationContextAwaiter(CefThreadId tid)
 {
     _threadId = tid;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// The post task.
 /// </summary>
 /// <param name="threadId">
 /// The thread id.
 /// </param>
 /// <param name="action">
 /// The action.
 /// </param>
 /// <param name="port">
 /// The port.
 /// </param>
 /// <param name="completionCallback">
 /// The completion callback.
 /// </param>
 private void PostTask(CefThreadId threadId, Action <int, Action> action, int port, Action completionCallback)
 {
     CefRuntime.PostTask(threadId, new ActionTask2(action, port, completionCallback));
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Method that will be executed.
 /// </summary>
 /// <param name="threadId">Thread executing the call.</param>
 protected abstract void Execute(CefThreadId threadId);
Ejemplo n.º 27
0
 public static extern int post_task(CefThreadId threadId, cef_task_t* task);
Ejemplo n.º 28
0
 /// <summary>
 /// Returns true (1) if this task runner is for the specified CEF thread.
 /// </summary>
 public unsafe virtual bool BelongsToThread(CefThreadId threadId)
 {
     return(SafeCall(NativeInstance->BelongsToThread(threadId) != 0));
 }
Ejemplo n.º 29
0
 public CefThreadSynchronizationContext(CefThreadId threadId)
 {
     this.threadId   = threadId;
     this.waitHandle = new AutoResetEvent(false);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// CEF maintains multiple internal threads that are used for handling
 /// different types of tasks.
 /// The UI thread creates the browser window and is used for all interaction with the WebKit rendering engine and V8 JavaScript engine
 /// (The UI thread will be the same as the main application thread if cef_initialize() is called with a CefSettings.multi_threaded_message_loop value of false (0).)
 /// The IO thread is used for handling schema and network requests.
 /// The FILE thread is used for the application cache and other miscellaneous activities.
 /// This function will return true (1) if called on the specified thread.
 /// </summary>
 public static bool CurrentlyOn(CefThreadId threadId)
 {
     return NativeMethods.cef_currently_on((cef_thread_id_t)threadId) != 0;
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Post a task for delayed execution on the specified thread. This function may
        /// be called on any thread. It is an error to request a thread from the wrong
        /// process.
        /// </summary>
        public static bool PostTask(CefThreadId threadId, CefTask task, long delay)
        {
            if (task == null) throw new ArgumentNullException("task");

            return libcef.post_delayed_task(threadId, task.ToNative(), delay) != 0;
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Post a task for delayed execution on the specified thread.
 /// This function may be called on any thread.
 /// </summary>
 public static void PostTask(CefThreadId threadId, CefTask task, long delayMs)
 {
     var result = NativeMethods.cef_post_delayed_task((cef_thread_id_t)threadId, task.GetNativePointerAndAddRef(), delayMs) != 0;
     if (!result) ThrowPostTaskError();
 }
Ejemplo n.º 33
0
 public static void PostTask(CefThreadId threadId, Action action)
 {
     CefRuntime.PostTask(threadId, new ActionTask(action));
 }
Ejemplo n.º 34
0
 public static int belongs_to_thread(cef_task_runner_t* self, CefThreadId threadId)
 {
     belongs_to_thread_delegate d;
     var p = self->_belongs_to_thread;
     if (p == _p5) { d = _d5; }
     else
     {
         d = (belongs_to_thread_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(belongs_to_thread_delegate));
         if (_p5 == IntPtr.Zero) { _d5 = d; _p5 = p; }
     }
     return d(self, threadId);
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Returns the task runner for the specified CEF thread.
 /// </summary>
 public static CefTaskRunner GetForThread(CefThreadId threadId)
 {
     return CefTaskRunner.FromNativeOrNull(cef_task_runner_t.get_for_thread(threadId));
 }
Ejemplo n.º 36
0
 public static extern cef_task_runner_t* get_for_thread(CefThreadId threadId);
Ejemplo n.º 37
0
 public static extern int CefCurrentlyOn(CefThreadId threadid);
Ejemplo n.º 38
0
 /// <summary>
 /// Returns the task runner for the specified CEF thread.
 /// </summary>
 public static CefTaskRunner GetForThread(CefThreadId threadId)
 {
     return(CefTaskRunner.Wrap(CefTaskRunner.Create, CefNativeApi.cef_task_runner_get_for_thread(threadId)));
 }
Ejemplo n.º 39
0
 protected override void Execute(CefThreadId threadId)
 {
     this.action();
 }
Ejemplo n.º 40
0
 public static extern int currently_on(CefThreadId threadId);
Ejemplo n.º 41
0
 /// <summary>
 /// The post task.
 /// </summary>
 /// <param name="threadId">
 /// The thread id.
 /// </param>
 /// <param name="action">
 /// The action.
 /// </param>
 /// <param name="address">
 /// The address.
 /// </param>
 /// <param name="port">
 /// The port.
 /// </param>
 /// <param name="completionCallback">
 /// The completion callback.
 /// </param>
 private void PostTask(CefThreadId threadId, Action <string, int, Action> action, string address, int port, Action completionCallback)
 {
     CefRuntime.PostTask(threadId, new ActionTask1(action, address, port, completionCallback));
 }
Ejemplo n.º 42
0
 public static extern int post_delayed_task(CefThreadId threadId, cef_task_t *task, long delay_ms);
Ejemplo n.º 43
0
 /// <summary>
 /// The post task.
 /// </summary>
 /// <param name="threadId">
 /// The thread id.
 /// </param>
 /// <param name="action">
 /// The action.
 /// </param>
 /// <param name="completionCallback">
 /// The completion callback.
 /// </param>
 private void PostTask(CefThreadId threadId, Action <Action> action, Action completionCallback)
 {
     CefRuntime.PostTask(threadId, new ActionTask3(action, completionCallback));
 }
 public CefThreadSynchronizationContext(CefThreadId threadId)
 {
     this.threadId = threadId;
     this.waitHandle = new AutoResetEvent(false);
 }
Ejemplo n.º 45
0
 public static extern int currently_on(CefThreadId threadId);
Ejemplo n.º 46
0
 public static extern int CefPostTask(CefThreadId threadid, IntPtr task);
Ejemplo n.º 47
0
 public static extern int post_delayed_task(CefThreadId threadId, cef_task_t* task, long delay_ms);
Ejemplo n.º 48
0
 /// <summary>
 /// Returns true if this task runner is for the specified CEF thread.
 /// </summary>
 public bool BelongsToThread(CefThreadId threadId)
 {
     return(cef_task_runner_t.belongs_to_thread(_self, threadId) != 0);
 }
Ejemplo n.º 49
0
 public static extern cef_task_runner_t *get_for_thread(CefThreadId threadId);
Ejemplo n.º 50
0
 public unsafe extern int BelongsToThread(CefThreadId threadId);
Ejemplo n.º 51
0
 public static extern int post_task(CefThreadId threadId, cef_task_t *task);
Ejemplo n.º 52
0
 public CefTaskScheduler(CefThreadId threadId)
 {
     ThreadId = threadId;
 }
Ejemplo n.º 53
0
 /// <summary>
 /// CEF maintains multiple internal threads that are used for handling different
 /// types of tasks in different processes. See the cef_thread_id_t definitions in
 /// cef_types.h for more information. This function will return true if called on
 /// the specified thread. It is an error to request a thread from the wrong
 /// process.
 /// </summary>
 public static bool CurrentlyOn(CefThreadId threadId)
 {
     return(libcef.currently_on(threadId) != 0);
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Returns the task runner for the specified CEF thread.
 /// </summary>
 public static CefTaskRunner GetForThread(CefThreadId threadId)
 {
     return(CefTaskRunner.FromNativeOrNull(cef_task_runner_t.get_for_thread(threadId)));
 }
Ejemplo n.º 55
0
 /// <summary>
 /// The post task.
 /// </summary>
 /// <param name="threadId">
 /// The thread id.
 /// </param>
 /// <param name="action">
 /// The action.
 /// </param>
 private static void PostTask(CefThreadId threadId, Action action)
 {
     CefRuntime.PostTask(threadId, new ActionTask(action));
 }
Ejemplo n.º 56
0
 protected override void Execute(CefThreadId threadId)
 {
     this.action();
 }