예제 #1
0
 private async Task RemoveHistoryEntry(CancellationToken ct, INavigationHistoryEntry arg)
 {
     if (arg.IsAlive)
     {
         var aliveEntry = (AliveNavigationHistoryEntry)arg;
         await ThreadPool.RunAsync(operation => _viewModelFactory.ReleaseViewModel(aliveEntry.ViewModel), WorkItemPriority.Low);
     }
 }
예제 #2
0
        /// <summary>
        ///     Executes an action, that takes one parameter, asynchronously.
        /// </summary>
        /// <typeparam name="T">the type of the parameter for the action</typeparam>
        /// <param name="action">the action to execute</param>
        /// <param name="parameter">the parameter to pass to the action</param>
        /// <param name="delay">
        ///     a delay in milliseconds to wait before the action is executed (pass a value
        ///     greate or equal to zero to execute the action without any delay)
        /// </param>
        public virtual void ExecuteAsync <T>(Action <T> action, T parameter, int delay = 0)
        {
            // start new thread from the thread pool and pass it the action and the parameter
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            ThreadPool.RunAsync(
                async =>
            {
                // check, if the action execution should be delayed
                if (delay > 0)
                {
                    Task.Delay(delay).Wait();
                }

                // execute the action
                action(parameter);
            }, WorkItemPriority.Normal);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }