user3413723 user3413723 - 1 year ago 95
C# Question

Application_End Not Running

I'm new to C#, so please bear with me.

I have a function that runs in the

function in the Global.asax.cs file, and this works fine when I start debugging.

But when I stop debugging, the function I have in the Application_End function doesn't seem to fire off. I'm wondering if this has to do with debugging, or is just an error in my code.

Answer Source

Its in general not a good idea to put a lot of code in Application_End that you need to rely on firing. 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.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download