Xamarin.Macでアプリ自身を再起動する
ソフトウェアのアップデートなどアプリ自身を再起動したいときがある。
実装
AppDelegateクラスのWillTerminateメソッドに再起動する処理を記述する。 この状態でRestartRequestedフラグにtrueを設定してアプリを終了すれば再起動になる。
public override void WillTerminate (NSNotification notification)
{
if (RestartRequested)
{
NSWorkspace.SharedWorkspace.LaunchApp (NSBundle.MainBundle.BundleIdentifier,
NSWorkspaceLaunchOptions.NewInstance | NSWorkspaceLaunchOptions.Async,
NSAppleEventDescriptor.NullDescriptor,
IntPtr.Zero);
}
}