/// <summary> /// Executes the action on the UI thread asynchronously. /// </summary> /// <param name="action">The action to execute.</param> public static void BeginOnUIThread(this System.Action action) { ValidateDispatcher(); #if WinRT var dummy = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action()); #else dispatcher.BeginInvoke(action); #endif }
/// <summary> /// Executes the action on the UI thread asynchronously. /// </summary> /// <param name="action">The action to execute.</param> public virtual void BeginOnUIThread(System.Action action) { ValidateDispatcher(); #if WINDOWS_UWP var dummy = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action()); #else dispatcher.BeginInvoke(action); #endif }
public void Invoke(T parameter) { if (dispatcher != null) { bool access; #if NETFX_CORE access = dispatcher.HasThreadAccess; #else access = dispatcher.CheckAccess(); #endif if (access) { ExecuteCallback(parameter); } else { #if NETFX_CORE dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ExecuteCallback(parameter)); #else dispatcher.BeginInvoke(new Action(() => ExecuteCallback(parameter))); #endif } } else { #if NETFX_CORE ThreadPool.RunAsync((x) => ExecuteCallback(parameter)); #else ThreadPool.QueueUserWorkItem((x) => ExecuteCallback(parameter)); #endif } }
/// <summary> /// This will add the action to a list of actions to perform at once in a Dispatcher.Invoke call. /// This has better performance than calling Dispatcher.BeginInvoke directly. /// </summary> /// <param name="action">The action to queue.</param> public static void QueueAction(Action action) { _pendingActionsExecute.Add(action); if (!_isDispatcherPending) { _isDispatcherPending = true; if (_dispatcher == null) { _dispatcher = CoreDispatcher.INTERNAL_GetCurrentDispatcher(); } _dispatcher.BeginInvoke((Action)(() => { if (_isDispatcherPending) // We check again in case it has been cancelled - not sure if useful though { ExecutePendingActions(); } })); } }