/// <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); }
/// <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; } } } }