An analysis of application classes in C # (WPF)

Source: Internet
Author: User

Application Class
Encapsulates a WFP application.
Namespaces: System.Windows
Syntax: public class Application:dispatcherobject, iqueryambient
You can see that application inherits the Dispatcherobject class and the iqueryambient interface.

First look at the Dispatcherobject class
Dispatcherobject class
Represents an object associated with a dispatcher
Namespaces: System.Windows.Threading
Syntax: Pulic abstract class Dispatcherobject

So what is dispatcher?
Dispatcher Class
Provides services for managing thread work item queues
Syntax: public sealed class Dispatcher

Here's a special talk about the dispatcher Invoke method (Action)
The thread synchronization dispatcher that executes the specified action is associated with it.
So what is action?

Action Delegate
Encapsulates a method that does not have parameters and does not return a value.
Syntax: public delegate void Action ()

Next look at the Iqueryambient interface
Iqueryambient Interface
Whether the query treats the specified property as an ambient property in the current scope.
Namespaces: System.Windows.Markup
Syntax: public interface Iqueryambient

The following describes the properties of several application classes
Current Property
Gets the application object for the current AppDomain
Syntax: public static application Current {get;}
Dispatcher Property
Gets the Dispatcher associated with this dispatcherobject. (inherited from Dispatcherobject.) )
Through the above basic knowledge of the reserve, we can write this code:

System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>{    StartCpuShow();}));

A lambda expression is used in the appeal code, and if you have questions, you can refer to the blog "Analyzing lambda Expressions in C #"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

An analysis of application classes in C # (WPF)

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.