Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

c# - host.OnAppDisposing Intermittently Invoked

When one wishes to dispose of IDisposable objects with OWIN, it was been widely recommended to use the CancellationToken from the host, should it be available, like so:

var context = new OwinContext(builder.Properties);

var token = context.Get<CancellationToken>("host.OnAppDisposing");

if (token != CancellationToken.None)
{
    token.Register(() =>
    {
      disposable.Dispose();
    });
}

I've registered some 12 objects for disposal with the above code inside of a foreach and I've found that some number of these will be called throughout the day leaving me with some resources MIA while the others remain as if nothing had happened.

Unfortunately, the documentation for both host.OnAppDisposing and the CancellationToken itself has offered me little information. There is no mention of lifecycle on the former and the latter has no mention regarding limits to Register.

Is there a consistent and well-documented way to handle resource disposal in a long-running ASP.NET application running on IIS?

question from:https://stackoverflow.com/questions/65910933/host-onappdisposing-intermittently-invoked

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...