关闭/暂停事件时Windows Store App / Metro不起作用

时间:2013-04-28 15:28:31

标签: events microsoft-metro windows-store-apps exit

我正在制作这个涉及两个在线玩家的游戏。如果退出应用程序,则应通知另一个应用程序。我正在使用onsuspend事件,但它不起作用。这是我的代码:

    public MainPage()
    {
        this.InitializeComponent();

        Application.Current.Suspending += Current_Suspending;
        // and a bunch of other stuff
    }

    private async void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
    {
        await game.leaveGame();
    }

非常感谢任何帮助。我100%确定game.leaveGame()函数有效 - 我已经测试过了。

1 个答案:

答案 0 :(得分:0)

一旦你从暂停事件应用程序返回暂停,所以在你的情况下async方法game.leaveGame()将无法完成。 尝试将代码更改为(假设game.leaveGame是同步方法):

public MainPage()
{
    this.InitializeComponent();

    Application.Current.Suspending += Current_Suspending;
    // and a bunch of other stuff
}

private void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
    game.leaveGame();
}

有关应用程序生命周期here的更多详细信息。