Share via


CoreApplication.RequestRestartAsync(String) Method

Definition

Restart the app.

public:
 static IAsyncOperation<AppRestartFailureReason> ^ RequestRestartAsync(Platform::String ^ launchArguments);
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<AppRestartFailureReason> RequestRestartAsync(winrt::hstring const& launchArguments);
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<AppRestartFailureReason> RequestRestartAsync(string launchArguments);
function requestRestartAsync(launchArguments)
Public Shared Function RequestRestartAsync (launchArguments As String) As IAsyncOperation(Of AppRestartFailureReason)

Parameters

launchArguments
String

Platform::String

winrt::hstring

The arguments to pass to the restarted instance.

Returns

The status of the restart request.

Attributes

Windows requirements

Device family
Windows 10 Fall Creators Update (introduced in 10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v5.0)

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.

Applies to

See also