All, I have used the Thread
and BackgroundWorker
classes with success to facilitate a smooth UI for a few small-scale applications. I have recently been given the job of converting a huge piece of code from serial to multi-threaded and I have some questions due to some comments I have seen on this very site. The code I have to convert makes a varying amount (usually a large number) of calls to SQL Server and these SQL queries can sometimes run for 30 minutes or so. As such, multi-threading is required.
I have already setup a test program using BackgroundWorker
and these run well. However, some say that due to the BackgroundWorker
using the Thread-Pool they should not be used for long running tasks. I have not read this anywhere (i.e. Joesph Albahari C# 4.0 In a Nutshell), and this contradicts MSDN. Should I be using BackgroundWorker
or Thread
for such purposes?
Thanks in advance.
A BackgroundWorker is a ready to use class in WinForms allowing you to execute tasks on background threads which avoids freezing the UI and in addition to this allows you to easily marshal the execution of the success callback on the main thread which gives you the possibility to update the user interface with the ...
BackgroundWorker, is a component in . NET Framework, that allows executing code as a separate thread and then report progress and completion back to the UI.
The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running.
The BackgroundWorker class is designed to start long-running tasks in a separate thread. This class is essentially a wrapper for the ThreadPool class and uses a thread pool in its implementation.
You can make use of asynchronous queries in ADO.NET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With