Let's take a look at a small example: C # open a control on the client. It takes about five seconds to load a lot of data in the control. If we open the control directly, it takes five seconds for the control to pop up. Of course, the user has killed it. At this time, we need to first load the control UI to the user to give it an illusion, and then load the data in the background. Let's take a look at how it works.
First, load a BackgroundWorder component in the panel, and then register several events when loading the form:
1. BackgroundWorder startup event. It is to load the code in the background for 5 seconds; The BackgroundWorder. DoWork event;
2. Events loading the BackgroundWorder. This event can be written into the current loading progress or error event; BackgroundWorder. ProgressChanged event;
3. BackgroundWorder end event. That is, when the data is loaded or an asynchronous error is prompted,
BackgroundWorder. RunWorkerCompleted event.