简体   繁体   English

Application_End未运行

[英]Application_End Not Running

I'm new to C#, so please bear with me. 我是C#的新手,所以请耐心等待。

I have a function that runs in the Application_Start function in the Global.asax.cs file, and this works fine when I start debugging. 我有一个在Global.asax.cs文件中的Application_Start函数中运行的函数,这在我开始调试时工作正常。

But when I stop debugging, the function I have in the Application_End function doesn't seem to fire off. 但是当我停止调试时,我在Application_End函数中的函数似乎没有启动。 I'm wondering if this has to do with debugging, or is just an error in my code. 我想知道这是否与调试有关,或者只是我的代码中的错误。

I guess the application never ended. 我猜应用程序永远不会结束。 While you are debugging (using Cassandra or IIS Express) or running an installation on IIS itself the application doesn't end when your debugging session ends. 在调试(使用Cassandra或IIS Express)或在IIS本身上运行安装时,应用程序不会在调试会话结束时结束。

On IIS it ends when the worker process stops. 在IIS上,它在工作进程停止时结束。 This happens automatically after some time, depending on your application pool settings. 这会在一段时间后自动发生,具体取决于您的应用程序池设置。

In Cassandra and IIS Express it will happen when the process ends gracefully . 在Cassandra和IIS Express中,当进程正常结束时会发生。 I wonder if they get ever called on a regular basis on those installations. 我想知道他们是否定期在这些装置上进行调用。

Its in general not a good idea to put a lot of code in Application_End that you need to rely on firing. 在Application_End中放入大量需要依赖触发的代码通常不是一个好主意。 Consider that an ApplicationInstance is started to each thread of the work process that will be serving your application, you will run into scenarios where your Application_End will be called frequently on a busy site as traffic ebbs and flows. 考虑到ApplicationInstance将启动到将为您的应用程序提供服务的工作进程的每个线程,您将遇到在忙碌的站点上频繁调用Application_End的情况,因为流量会消耗和流动。

You may find it easier to use a Cache object with a sliding expiration and a callback function when the object expires from Cache to ensure that your clean up code is called properly when you need it. 当对象从Cache到期时,您可能会发现使用具有滑动过期和回调函数的Cache对象更容易,以确保在需要时正确调用清理代码。

http://msdn.microsoft.com/en-us/library/05kd8d77(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/05kd8d77(v=vs.110).aspx

I had a similar issue where Application_End was not called because there were threads running when the application was asked to stop, and because this method is only called after everything has stopped fine. 我有一个类似的问题,其中没有调用Application_End ,因为当要求停止应用程序时有线程运行,并且因为只有在一切都停止正常后调用此方法。

Then, I discovered Application_Disposed . 然后,我发现了Application_Disposed From http://www.techrepublic.com/article/working-with-the-aspnet-globalasax-file/5771721/ : 来自http://www.techrepublic.com/article/working-with-the-aspnet-globalasax-file/5771721/

Application_Disposed: Fired just before an application is destroyed. Application_Disposed:在销毁应用程序之前触发。 This is the ideal location for cleaning up previously used resources. 这是清理以前使用的资源的理想位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM