alphacloud / Autofac.Extras.Quartz

Autofac integration for Quartz.Net
MIT License
121 stars 38 forks source link

Correct way of stopping scheduler #212

Closed Bykiev closed 2 years ago

Bykiev commented 2 years ago

Hi, we're using Quartz.NET in our ASP. NET Web API project. We're not calling Shutdown and because of this sometime after deploy old scheduler is still running along side with started new schduler. The correct way will be calling Shutdown on Application_End, but I can't get the instance of scheduler, here is an error:

Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed.

What is the correct way of getting scheduler instance here?

Bykiev commented 2 years ago

As I'm using the OWIN, the correct way was using Registerdelegeate:

var properties = new AppProperties(app.Properties);
var token = properties.OnAppDisposing;

if (token != System.Threading.CancellationToken.None)
{
     token.Register(() =>
     {
         // shutdown here
     })
}