AppInstance.Restart(String) 方法

定义

重启应用程序实例。

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

参数

arguments
String

Platform::String

winrt::hstring

要传递给重启实例的参数。

返回

重启请求的状态。

示例

在此示例中,假设应用在初始化期间遇到错误。 应用显示一个错误对话框,在用户单击“确定”后,应用必须重启。 该示例输出这些用例的调试信息。

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;
    }
}

适用于

另请参阅