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)