示例#1
0
        /// <summary>
        /// Queues the specified task for execution.
        /// </summary>
        /// <param name="task"><see cref="BackgroundTask"/> to be executed.</param>
        public static void ExecuteLater(BackgroundTask task)
        {
            if (task == null)
                throw new ArgumentNullException("task");

            _tasksToExecute.Value.Add(task);
        }
示例#2
0
        /// <summary>
        /// Immediately executes given background task.
        /// </summary>
        /// <param name="task"><see cref="BackgroundTask"/> to execute.</param>
        public static void ExecuteTask(BackgroundTask task)
        {
            if (task == null)
                throw new ArgumentNullException("task");
            if (SessionFactory == null)
                throw new InvalidOperationException("SessionFactory is not initialized.");

            // If task execution fails then retry a number of times.
            for (int i = 0; i < 10; i++)
            {
                using (var session = SessionFactory.OpenSession())
                {
                    switch (task.Run(session))
                    {
                        case true:
                        case false:
                            return;
                        case null:
                            break;
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Immediately executes given background task.
        /// </summary>
        /// <param name="task"><see cref="BackgroundTask"/> to execute.</param>
        public static void ExecuteTask(BackgroundTask task)
        {
            if (task == null)
                throw new ArgumentNullException("task");
            if (SessionFactory == null)
                throw new InvalidOperationException("SessionFactory is not initialized.");

            // If task execution fails then retry a number of times.
            for (int i = 0; i < 10; i++)
            {
                using (var session = SessionFactory.OpenSession())
                {
                    switch (task.Run(session))
                    {
                        case true:
                        case false:
                            return;
                        case null:
                            break;
                    }
                }
            }
        }