CoreApplication Class

Definition

Enables apps to handle state changes, manage windows, and integrate with a variety of UI frameworks.

public ref class CoreApplication abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Muse(Version=100794368)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication3, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationExit, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication2, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUseCount, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class CoreApplication abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Muse(Version=100794368)]
/// [Windows.Foundation.Metadata.WebHostHidden]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUseCount, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationExit, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication3, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication2, 65536, "Windows.Foundation.UniversalApiContract")]
class CoreApplication abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Muse(Version=100794368)]
/// [Windows.Foundation.Metadata.WebHostHidden]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUseCount, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationExit, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication3, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication2, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication2, 196608, "Windows.Foundation.UniversalApiContract")]
class CoreApplication abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Muse(Version=100794368)]
/// [Windows.Foundation.Metadata.WebHostHidden]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUseCount, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationExit, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication3, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreImmersiveApplication2, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication2, 196608, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Static(Windows.ApplicationModel.Core.ICoreApplication3, 327680, "Windows.Foundation.UniversalApiContract")]
class CoreApplication abstract sealed
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Muse(Version=100794368)]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication3), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationExit), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication2), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUseCount), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.WebHostHidden]
public static class CoreApplication
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Muse(Version=100794368)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUseCount), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationExit), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication3), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication2), 65536, "Windows.Foundation.UniversalApiContract")]
public static class CoreApplication
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Muse(Version=100794368)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUseCount), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationExit), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication3), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication2), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication2), 196608, "Windows.Foundation.UniversalApiContract")]
public static class CoreApplication
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Muse(Version=100794368)]
[Windows.Foundation.Metadata.WebHostHidden]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUseCount), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationExit), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplicationUnhandledError), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication3), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreImmersiveApplication2), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication2), 196608, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Static(typeof(Windows.ApplicationModel.Core.ICoreApplication3), 327680, "Windows.Foundation.UniversalApiContract")]
public static class CoreApplication
Public Class CoreApplication
Inheritance
CoreApplication
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

The system creates this object as a singleton when it runs the app. It is run as an Application Single-Threaded Apartment (ASTA). Threads created from the app singleton, such as the view provider (seen in the sample below), should be attributed as Multi-Threaded Apartment (MTAThread).

This API is supported in native apps only, except for the Properties property, which is always available.

struct App : implements<App, IFrameworkViewSource, IFrameworkView>
{
public:
    IFrameworkView CreateView()
    {
        return *this;
    }
};

...

int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
{
    Windows::ApplicationModel::Core::CoreApplication::Run(App());
}
ref class MyFrameworkViewSource : IFrameworkViewSource
{
public:
    virtual IFrameworkView^ CreateView()
    {
        return ref new MyFrameworkView();
    }
};

// ...

[Platform::MTAThread]
int main(Platform::Array<Platform::String^>^)
{
    auto frameworkViewSource = ref new MyFrameworkViewSource();
    Windows::ApplicationModel::Core::CoreApplication::Run(frameworkViewSource);
    return 0;
}
internal class ApplicationSource : IFrameworkViewSource
{
	public virtual IFrameworkView CreateView()
	{
		return new CoreApp();
	}
}

...

[MTAThread]
public static int Main()
{
	var appSource = new ApplicationSource();
	CoreApplication.Run(appSource);
	return 0;
}

Version history

Windows version SDK version Value added
1607 14393 BackgroundActivated
1607 14393 EnablePrelaunch
1607 14393 EnteredBackground
1607 14393 LeavingBackground
1709 16299 RequestRestartAsync
1709 16299 RequestRestartForUserAsync

Properties

Id

Gets the package-relative app identifier for the process.

MainView

Gets the main CoreApplicationView instance for all running apps that use this CoreApplication instance.

Properties

Gets a property set that the app and UI frameworks can use to store info while the process is running.

Views

Gets all views for the app.

Methods

CreateNewView()

Creates a new view for the app.

CreateNewView(IFrameworkViewSource)

Creates a new view for the app.

CreateNewView(String, String)

Creates a new view for the app.

DecrementApplicationUseCount()

Decrements the total count of running app instances that use this CoreApplication instance.

EnablePrelaunch(Boolean)

Enable or disable the operating system's ability to prelaunch your app.

Exit()

Shuts down the app.

GetCurrentView()

Gets the active view for the app.

IncrementApplicationUseCount()

Increments the total count of running app instances that use this CoreApplication instance.

RequestRestartAsync(String)

Restart the app.

RequestRestartForUserAsync(User, String)

Restart the app in the context of a different user.

Run(IFrameworkViewSource)

Runs an external view provider factory to obtain a view provider.

RunWithActivationFactories(IGetActivationFactory)

Runs an activatable type factory to obtain an external activatable type.

Events

BackgroundActivated

Fired when your app is activated by a background trigger.

EnteredBackground

Fired when the app enters the running in the background state.

Exiting

Occurs when the app is shutting down.

LeavingBackground

Fired just before application UI becomes visible.

Resuming

Occurs when an app is resuming.

Suspending

Occurs when the app is suspending.

UnhandledErrorDetected

Occurs when there is an underlying error that is routed to the CoreApplication instance, as part of global error handling logic.

Applies to

See also