共用方式為


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

適用於

另請參閱