开发者

ASP.NET application stopping event?

I have a ASP.NET application which implements a custom in-memory cache. I'm using this as opposed to ASP.NET's caching mechanism as I needed a more complex way to h开发者_开发技巧andle what to drop from the cache. Part of this custom cache is a separate thread which occasionally searches for data to drop from the cache whenever it gets too large.

What I need to do is signal this cache maintenance thread to stop whenever the ASP.NET application 'exits'. I guess this basically amounts to when the web site is stopped in IIS.

Is there a pre-existing event I can utilise to do this? Thanks.


You can create a Global.asax file and override the Application_End method.

http://www.csharphelp.com/2006/06/setting-up-global-objects-with-the-global-asax-file/


From the moment that you have this custom, memory cache, I suppose that your asp.net application communicate with this cache in many ways.

So why not make an a global value on this cashe, and make somthing like that on global.asax

void Application_Start(object sender, EventArgs e) 
{
  GlobalCacheUsed ++;
}

void Application_End(object sender, EventArgs e) 
{
  GlobalCacheUsed --;
}

and your thread just check for that GlobalCacheUsed value

Can I please ask you witch way you use to communicate with your apps ? I have make something similar with you, having class that I use both a database table and other cache that use a memory. My trigger to clear the cache is with user events, or with timers.

Hope this help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜