Last post Dec 16, 2016 07:56 PM by deepalgorithm
Dec 16, 2016 03:05 PM|williamj7|LINK
I have a background worker in an ASP.NET Web application that runs in a loop.
Do I need to Dispose the object on Page closing?
Dec 16, 2016 04:31 PM|PatriceSc|LINK
You mean a System.Component.BackgroundWorker? I'm even surprised that it works. It is intended to update a UI from a background process which doesn't make really sense for a web app (as the UI is rendered as HTML and then shown by the browser). To me it
is rather intended for Windows based applications...
Else it depends if at this point you are done with it. You still have some background work that runs or it is completed already at this step?
Dec 16, 2016 04:48 PM|deepalgorithm|LINK
Is the class you are using?
If it is, then no you do not need to dispose.
BackgroundWorker derives from Component. Component implements the IDisposable interface. This makes BackgroundWorker inherit the Dispose() method. A Backgroundworker is a relatively 'light' object, it holds no resources. The thread is borrowed from
If you are using ASP.NET and you want to run a background task, then at a
minimum you should use HostingEnvironment.QueueBackgroundWorkItem. A more robust alternative is to use something like
QueueBackgroundWorkItem will register the work with ASP.NET. When ASP.NET has to recycle, it will notify the background work and will then wait up to 30 seconds for the work to complete. If the background work does not complete within that time, the work
// your code
catch (Exception ex)
// handle & log exception
Dec 16, 2016 07:40 PM|williamj7|LINK
Yes, I am using BackgroundWorker.
What do you recommend?
Dec 16, 2016 07:56 PM|deepalgorithm|LINK
See my answer, I've updated it.