C # BackgroundWorker

Source: Internet
Author: User

The BackgroundWorker object has three main events:

DoWork- fires when a multithreaded operation of the BackgroundWorker object is executed.
-
-

workerreportsprogress -If you want the BackgroundWorker object to report the thread's real-time progress asynchronously, you must set the value of the property to true.


The reportprogress method of the BackgroundWorker object is used to return the real-time progress performed by the background thread to the main thread.

InvokeRequired and Invoke

C # prohibits direct access to controls across threads, InvokeRequired is created to solve this problem, and when a control's InvokeRequired property value is true, it is stated that a thread other than the one that created it wants to access it.
At this point it will call new MethodInvoker (Loadglobalimage) internally to complete the following steps, which guarantees the security of the control, and the controls in Windows forms are bound to a specific thread without thread safety. Therefore, if you invoke a control's method from another thread, you must use an Invoke method of the control to marshal the call to the appropriate thread.

For the above content hereby made an example, the effect is as follows (more ugly, just for the sake of contact), do data processing including imported Excel tools can learn from, but the corresponding logic to modify the following:

Click I download source code

C # BackgroundWorker

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.