public void ConfigureServices(IServiceCollection services) { //InvalidOperationException: Synchronous operations are disallowed. //Call WriteAsync or set AllowSynchronousIO to true instead // If using Kestrel: services.Configure <KestrelServerOptions>(options => { options.AllowSynchronousIO = true; }); // If using IIS: services.Configure <IISServerOptions>(options => { options.AllowSynchronousIO = true; }); services.AddSingleton(new AppSettings(Configuration)); //添加Quartz服务 //用于创建作业实例 services.AddSingleton <IJobFactory, SingletonJobFactory>(); //处理调度和管理作业 services.AddSingleton <ISchedulerFactory, StdSchedulerFactory>(); services.AddSingleton <QuartzJobRunner>(); //添加我们的Job services.AddQuartzJobSetup(); services.AddSingleton <QuartzHostedService>(); services.AddSingleton <IHostedService, QuartzHostedService>(); AutofacExtension.InitialAutofac(); services.AddControllers(); }