Whether in winform or WPF, we need to make a progress bar for a large loop or time-consuming processing. The first thing we think of is multithreading. Otherwise, the progress bar will be suspended and will not be updated. Multithreading is troublesome. If you just update the UI, you can use systems. doevents.
In winform, the message queue is processed using peekmessage, which gives the UI the opportunity to update. In WPF, pushframe can be used in dispatch to achieve the same effect.
Code:
- Code:
- Public void doevents ()
- {
- Dispatcherframe frame = new dispatcherframe ();
- Dispatcher. currentdispatcher. begininvoke (dispatcherpriority. background,
- New dispatcheroperationcallback (delegate (Object F)
- {
- (Dispatcherframe) f). Continue = false;
- Return NULL;
- }
- ), Frame );
- Dispatcher. pushframe (FRAME );
- }
After writing this method, we can call doevents () after the UI to be updated in a loop or event.