[Plug-in framework Exploration Series] use multiple UI threads to improve performance

Source: Internet
Author: User

All users who know about the WPF thread model know that the UI thread is responsible for rendering and managing the UI, while the UI element (derived from

Dispatcherobject) can only be accessed by the thread that creates this element, which causes some time-consuming UI operations

The entire applicationProgramPerformance, unresponsiveness, and long waits sometimes make people crazy, And the UI thread once became an indispensable

The wider the gap.
For the framework, the behavior of a plug-in should not affect the stability of other plug-ins and the entire platform.

Running WPF application with multiple UI threads and dispatcherobject and WPF line

Cheng ModelArticleAfter that, the idea was opened immediately. The previous article described how to use multiple UI lines in the WPF application.

If each independent plug-in is in a different UI thread, the natural performance will be improved.

The message loop of Win32 and the thread model of WPF are analyzed thoroughly.
The following describes how to create a new UI thread.

Thread thread = new thread () => {window win = new window {Title = string. format ("thread ID: {0}", thread. currentthread. managedthreadid)}; win. show (); dispatcher. run () ;}); thread. isbackground = true; thread. setapartmentstate (apartmentstate. sta); thread. start ();

In this way, the window will run in the new thread, dispatcher. Run () will bring the current thread into the message loop, and set the isbackground of the thread to true to ensure that the program is exited.

The thread is automatically recycled when it is released; otherwise, the process will reside.

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.