AspNetBackgroundTasks icon indicating copy to clipboard operation
AspNetBackgroundTasks copied to clipboard

Documentation lacks details on how to call a long background task with Shutdown token

Open sun21170 opened this issue 11 years ago • 2 comments

I noticed there are 3 different ways described to run a long-running task in ASP.Net so its immune to AppDomains recycling. However, the last of these where a ShutDown token is passed to the method is not clear. Could you add more explanation on how this token can be used inside the long running method 'MyWorkAsync'? What if I don't pass this token, what will be its effects and whether the long task will still go to completion in case of AppDomain shutdown? BackgroundTaskManager.Run(async () => { await MyWorkAsync(BackgroundTaskManager.Shutdown); });

sun21170 avatar Jul 28 '14 15:07 sun21170

The token is there so that your task is aware of when ASP.NET is trying to shut down the AppDomain. The AspNetBackgroundTasks library will wait for your task to complete before allowing ASP.NET to shut down the AppDomain.

StephenCleary avatar Aug 01 '14 19:08 StephenCleary

Stephen, Thanks for your clarification. I figured it out. I use it to end my long background job in case the token has a cancellation request and exit the main loop in my background method's code. if (token != null && token.IsCancellationRequested) //from within the background code method { prog.ProgressText = "App Pool recycled"; break; }

I am using your framework for running background code and so far its all going very well. Actually, right now when users click on Submit button in one of my ASP.Net pages, the code can take a long time and I am finding that if it takes more than 4 minutes or so, the IE browser gives up and says Page cannot be displayed, even though the code runs to completion on web server due to execution timeout of 3600 seconds. While researching this problem, I came across your framework and decided to use it to solve this browser timeout problem and in my tests it is proving excellent so far.
Thanks once again for providing your excellent code.

sun21170 avatar Aug 01 '14 23:08 sun21170