Encapsulate the BackgroundWorker control (source code download is provided, and F5 indicates the visible effect)

Source: Internet
Author: User

Demo source code

Background

Some small programs or demos often use Asynchronization and multithreading to execute some time-consuming work and timely feedback the progress. I usually use the BackgroundWorker Control located in the [System. ComponentModel] namespace. Although the properties and events of the control are simple, I will always forget it. Therefore, the purpose of this article is to encapsulate the BackgroundWorker control. I only need to pay attention to what I want to do (DoWork), what I want to do (RunWorkerCompleted), and the progress feedback (ProgressChanged.

Project Structure Overview

The following is the Demo project structure:

Simplest call

The encapsulated BackgroundWorker class provides a default implementation for each event. Therefore, it is especially simple to use in projects in the console test project. See the following code:

BackgroundWorker bw =

Running:

Summary

It's just a small package, and the code is very simple. From then on, our partners can use this package to avoid forgetting it, and use it more concisely!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.