AppInstance.Restart(String) Method

Definition

Restarts the application instance.

public:
 static AppRestartFailureReason Restart(Platform::String ^ arguments);
 static AppRestartFailureReason Restart(winrt::hstring const& arguments);
public static AppRestartFailureReason Restart(string arguments);
function restart(arguments)
Public Shared Function Restart (arguments As String) As AppRestartFailureReason

Parameters

arguments
String

Platform::String

winrt::hstring

The arguments to pass to the restarted instance.

Returns

The status of the restart request.

Examples

In this example, assume the app has encountered an error during initialization. The app displays an error dialog, and after the user clicks OK the app must restart. The example outputs debug info for these use cases.

using Windows.ApplicationModel.Core;
using Microsoft.Windows.AppLifecycle;
using System.Diagnostics;
...
private void HandleInitializationError()
{   
    // Restart app in safe mode to avoid another initialization failure.
    // Note: Your app would need to handle the 'safemode' argument and
    //       implement a safe mode experience in this scenario.
    AppRestartFailureReason reason = AppInstance.Restart("/safemode");
    switch (reason)
    {
        case AppRestartFailureReason.RestartPending:
            Debug.WriteLine("Another restart is currently pending.");
            break;
        case AppRestartFailureReason.InvalidUser:
            Debug.WriteLine("Current user is not signed in or not a valid user.");
            break;
        case AppRestartFailureReason.Other:
            Debug.WriteLine("Failure restarting.");
            break;
    }
}

Applies to

See also