public static async Task Main(string[] args) { IConfiguration configuration = new ConfigurationBuilder() .SetBasePath(System.IO.Directory.GetCurrentDirectory()) //From NuGet Package Microsoft.Extensions.Configuration.Json .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); LogManager.Configuration = new NLogLoggingConfiguration(configuration.GetSection("NLog")); Logger logger = LogManager.GetCurrentClassLogger(); try { IServiceProvider serviceProvider = SetupDependencyInjection(configuration); ITasksRunner tasksRunner = serviceProvider.GetRequiredService <ITasksRunner>(); await tasksRunner.ExecuteAsync(); } catch (Exception ex) { // NLog: catch any exception and log it. logger.Error(ex, "Stopped program because of exception"); throw; } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) LogManager.Shutdown(); } }
public ExecutionContext(ITasksRunner tasksRunner, int taskId) { if (tasksRunner == null) { throw new ArgumentNullException("tasksRunner"); } _tasksRunner = tasksRunner; TaskId = taskId; }
public BlockingTaskHost(ITasksRunner runner, TimeSpan timeout) { if (runner == null) { throw new ArgumentNullException("runner"); } if (timeout < TimeSpan.Zero) { throw new ArgumentOutOfRangeException("timeout", timeout, "The timeout must greater than or equal to zero."); } _runner = runner; _timeout = timeout; }