Cheap Dedicated Server -Application Management,Getting the Current Application

Getting the Current Application

Because the services of the Application class are shared across an application, there can be only one instance of the Application class per AppDomain. To enforce this, the Application class is implemented as a singleton class (see Implementing Singleton in C#), which creates a single instance of itself and provides shared access to it with the static Current property.

The following code shows how to acquire a reference to the Application object for the current AppDomain.
C#  VB
// Get current application
Application current = App.Current;

Current returns a reference to an instance of the Application class. If you want a reference to your Application derived class you must cast the value of the Current property, as shown in the following example.
C#  VB
// Get strongly-typed current application
App app = (App)App.Current;

You can inspect the value of Current at any point in the lifetime of an Application object. However, you should be careful. After the Application class is instantiated, there is a period during which the state of the Application object is inconsistent. During this period, Application is performing the various initialization tasks that are required by your code to run, including establishing application infrastructure, setting properties, and registering events. If you try to use the Application object during this period, your code may have unexpected results, particularly if it depends on the various Application properties being set.

When Application completes its initialization work, its lifetime truly begins.


You may like My previous post :
      Cheap Dedicated Server -Management

Cheap Dedicated Server -Application Management,Getting the Current Application Cheap Dedicated Server -Application Management,Getting the Current Application Reviewed by Cheap VPS on 00:43 Rating: 5

No comments:

Powered by Blogger.