CoreApplication.RequestRestartAsync(String) CoreApplication.RequestRestartAsync(String) CoreApplication.RequestRestartAsync(String) CoreApplication.RequestRestartAsync(String) Method

Definition

Restart the app.

public : static IAsyncOperation<AppRestartFailureReason> RequestRestartAsync(Platform::String launchArguments)
static IAsyncOperation<AppRestartFailureReason> RequestRestartAsync(winrt::hstring launchArguments) const;
public static IAsyncOperation<AppRestartFailureReason> RequestRestartAsync(String launchArguments)
Public Shared Function RequestRestartAsync(launchArguments As String) As IAsyncOperation(Of AppRestartFailureReason)

Parameters

launchArguments
String String

The arguments to pass to the restarted instance.

Returns

Additional features and requirements

Device family
Windows 10 Fall Creators Update (introduced v10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Examples

private async void DoMajorAppReconfiguration()
{
    // Attempt restart, with arguments.
    AppRestartFailureReason result =
        await CoreApplication.RequestRestartAsync("-fastInit -level 1 -foo");

    // Restart request denied, send a toast to tell the user to restart manually.
    if (result == AppRestartFailureReason.NotInForeground
        || result == AppRestartFailureReason.Other)
    {
        SendToast("Please manually restart.");
    }
}

Remarks

  • The app must be visible and foreground when it calls this API.
  • If the restart fails, but the user subsequently launches the app manually, the app will launch normally and no restart arguments will be passed.
  • If the app wasn't launched in the normal way, but was launched by a share contract, file picker, app-service, and so on, the app should not call this API because the user will not expect the resulting behavior.
  • The app should not request an Extended Execution session after it has called this API because that will result in a poor user experience.
  • If the app has any in-process background tasks running when it calls this API, those tasks will be cancelled in the normal way. Out-of-process background tasks will not be affected.
  • When the app is restarted, LaunchActivatedEventArgs.PreviousExecutionState will have the value Terminated so that the app can distinguish between a resume and a restart.

See also

  • Windows.ApplicationModel.Core.CoreApplication.RequestRestartForUserAsync(Windows.System.User,System.String) [How to restart your app programmatically](https://blogs.windows.com/buildingapps/2017/07/28/restart-app-programmatically/#oPS3xDHQYpflJRkA.97)