public static IBackgroundProcessDispatcherBuilder UseBackgroundPool(
            [NotNull] this IBackgroundProcessAsync process,
            int maxConcurrency,
            [NotNull] Func <string, ThreadStart, IEnumerable <Thread> > threadFactory)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (maxConcurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
            }
            if (threadFactory == null)
            {
                throw new ArgumentNullException(nameof(threadFactory));
            }

            Func <TaskScheduler> createScheduler = () => new BackgroundTaskScheduler(
                threadStart => threadFactory(process.GetType().Name, threadStart),
                exception =>
            {
                LogProvider.GetLogger(typeof(BackgroundTaskScheduler)).FatalException(
                    "Unhandled exception occurred in scheduler. Please report it to Hangfire developers",
                    exception);
            });

            return(new BackgroundProcessDispatcherBuilderAsync(process, createScheduler, maxConcurrency, true));
        }
 public static IBackgroundProcessDispatcherBuilder UseBackgroundPool(
     [NotNull] this IBackgroundProcessAsync process,
     int maxConcurrency)
 {
     return(UseBackgroundPool(
                process,
                maxConcurrency,
                maxConcurrency < Environment.ProcessorCount ? maxConcurrency : Environment.ProcessorCount));
 }
        public static IBackgroundProcessDispatcherBuilder UseThreadPool(
            [NotNull] this IBackgroundProcessAsync process,
            int maxConcurrency)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (maxConcurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
            }

            return(new BackgroundProcessDispatcherBuilderAsync(process, () => TaskScheduler.Default, maxConcurrency, false));
        }
        public static IBackgroundProcessDispatcherBuilder UseBackgroundPool(
            [NotNull] this IBackgroundProcessAsync process,
            int maxConcurrency,
            int threadCount)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (maxConcurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
            }
            if (threadCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(threadCount));
            }

            return(UseBackgroundPool(
                       process,
                       maxConcurrency,
                       (threadName, threadStart) => DefaultThreadFactory(threadCount, threadName, threadStart)));
        }
예제 #5
0
        public BackgroundProcessDispatcherBuilderAsync(
            [NotNull] IBackgroundProcessAsync process,
            [NotNull] Func <TaskScheduler> taskScheduler,
            int maxConcurrency,
            bool ownsScheduler)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (taskScheduler == null)
            {
                throw new ArgumentNullException(nameof(taskScheduler));
            }
            if (maxConcurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxConcurrency));
            }

            _process        = process;
            _taskScheduler  = taskScheduler;
            _maxConcurrency = maxConcurrency;
            _ownsScheduler  = ownsScheduler;
        }
 public static IBackgroundProcessDispatcherBuilder UseBackgroundPool(
     [NotNull] this IBackgroundProcessAsync process)
 {
     return(UseBackgroundPool(process, Environment.ProcessorCount));
 }