Link for code samples used in the demo
Link for all dot net and sql server video tutorial playlists
In this video, we will discuss the use of BackgroundWorker Class in windows forms application with an example. Along the way, we will also discuss using progressbar control.
First, let’s understand, why should we use BackgroundWorker Class?
By default windows applications are single threaded. This means, when we run the application there will be a single thread which is commonly called as UI thread. This is the thread that is responsible for doing all the work, that is
1. Creating and updating user interface elements and
2. Executing application code
For example, let’s say we have a function that takes 10 seconds to complete. While the UI thread is busy processing this function, the UI of the application is frozen and the end user cannot interact with the controls on the form during those 10 seconds. To keep our application responsive, we can create a new Thread ourselves and then ask that thread to execute the function that takes long time to complete, so that the UI thread is free to update the controls on the form. But the problem with creating threads ourselves is that, it can get extremely complex especially when we have to update UI controls based on the status of the thread function execution. It’s dangerous to access UI objects on a thread that didn’t create them. So the better option here is to use, BackgroundWorker Class which simplifies multithreading.
Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe