「Xamarin.Macでアプリ自身を再起動する」の版間の差分

ページの作成:「ソフトウェアのアップデートなどアプリ自身を再起動したいときがある。 == 実装 == AppDelegateクラスのWillTerminateメソッドに再…」
 
5行目: 5行目:
この状態でRestartRequestedフラグにtrueを設定してアプリを終了すれば再起動になる。
この状態でRestartRequestedフラグにtrueを設定してアプリを終了すれば再起動になる。
<source lang="csharp">
<source lang="csharp">
public override void WillTerminate (NSNotification notification)
[Register("AppDelegate")]
public class AppDelegate : NSApplicationDelegate
{
{
     if (RestartRequested)
     // 〜〜〜 中略 〜〜〜
 
    // 再起動フラグ
    public bool RestartRequested = false;
 
    // アプリ終了時に呼ばれる
    public override void WillTerminate (NSNotification notification)
     {
     {
         NSWorkspace.SharedWorkspace.LaunchApp (NSBundle.MainBundle.BundleIdentifier,
         // 再起動フラグ
                                                NSWorkspaceLaunchOptions.NewInstance | NSWorkspaceLaunchOptions.Async,
        if (RestartRequested)
                                                NSAppleEventDescriptor.NullDescriptor,
        {
                                                IntPtr.Zero);
            // 自分自身を起動
            NSWorkspace.SharedWorkspace.LaunchApp (
                NSBundle.MainBundle.BundleIdentifier,
                NSWorkspaceLaunchOptions.NewInstance | NSWorkspaceLaunchOptions.Async,
                NSAppleEventDescriptor.NullDescriptor,
                IntPtr.Zero);
        }
     }
     }
}
}
</source>
</source>


[[category: Xamarin.Mac]]
[[category: Xamarin.Mac]]