コード例 #1
0
        /// <summary>
        /// Processes asynchrounously the specified action with possibilty to retry on error.
        /// </summary>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="exceptionService">The exception service.</param>
        /// <param name="action">The action.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">The <paramref name="action"/> is <c>null</c>.</exception>
        public static async Task <TResult> ProcessWithRetryAsync <TResult>(this IExceptionService exceptionService, Func <TResult> action, CancellationToken cancellationToken = new CancellationToken())
        {
            Argument.IsNotNull("exceptionService", exceptionService);
            Argument.IsNotNull("action", action);

#if NET40 || SL5 || PCL
            return(await Task.Factory.StartNew(() => exceptionService.ProcessWithRetry(action), cancellationToken).ConfigureAwait(false));
#else
            return(await Task.Run(() => exceptionService.ProcessWithRetry(action), cancellationToken).ConfigureAwait(false));
#endif
        }
コード例 #2
0
        /// <summary>
        /// Processes asynchrounously the specified action with possibilty to retry on error.
        /// </summary>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="exceptionService">The exception service.</param>
        /// <param name="action">The action.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">The <paramref name="action"/> is <c>null</c>.</exception>
        public static Task <TResult> ProcessWithRetryAsync <TResult>(this IExceptionService exceptionService, Func <TResult> action, CancellationToken cancellationToken = new CancellationToken())
        {
            Argument.IsNotNull("exceptionService", exceptionService);
            Argument.IsNotNull("action", action);

            return(TaskHelper.Run(() => exceptionService.ProcessWithRetry(action), cancellationToken));
        }
コード例 #3
0
        /// <summary>
        /// Processes the specified action with possibilty to retry on error.
        /// </summary>
        /// <param name="exceptionService">The exception service.</param>
        /// <param name="action">The action.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="action"/> is <c>null</c>.</exception>
        public static void ProcessWithRetry(this IExceptionService exceptionService, Action action)
        {
            Argument.IsNotNull("exceptionService", exceptionService);
            Argument.IsNotNull("action", action);

            exceptionService.ProcessWithRetry(() => { action(); return(default(object)); });
        }