小编Wal*_*ski的帖子

我如何等待C#中的事件?

我正在创建一个包含一系列事件的类,其中一个是GameShuttingDown.触发此事件时,我需要调用事件处理程序.此事件的目的是通知用户游戏正在关闭,他们需要保存他们的数据.保存是等待的,事件不是.因此,当处理程序被调用时,游戏会在等待处理程序完成之前关闭.

public event EventHandler<EventArgs> GameShuttingDown;

public virtual async Task ShutdownGame()
{
    await this.NotifyGameShuttingDown();

    await this.SaveWorlds();

    this.NotifyGameShutDown();
}

private async Task SaveWorlds()
{
    foreach (DefaultWorld world in this.Worlds)
    {
        await this.worldService.SaveWorld(world);
    }
}

protected virtual void NotifyGameShuttingDown()
{
    var handler = this.GameShuttingDown;
    if (handler == null)
    {
        return;
    }

    handler(this, new EventArgs());
}
Run Code Online (Sandbox Code Playgroud)

活动报名

// The game gets shut down before this completes because of the nature of how events work
DefaultGame.GameShuttingDown += async (sender, args) => await this.repo.Save(blah); …
Run Code Online (Sandbox Code Playgroud)

c# events asynchronous

65
推荐指数
3
解决办法
6万
查看次数

圆圈中感叹号的字符代码是什么?

圆圈中感叹号的Unicode或Segoe UI符号(或其他字体)代码是什么?

在此输入图像描述

unicode symbols character non-ascii-characters

10
推荐指数
1
解决办法
1万
查看次数

"与活动文档同步"按钮不适用于某些文件

我使用Microsoft Visual Studio Ultimate 2013,看起来这个按钮在一个项目(WPF应用程序)中工作,而不是在同一个解决方案中的其他项目(服务器应用程序)中工作.哪个VS设置我可能已经坏了?

projects-and-solutions visual-studio

5
推荐指数
2
解决办法
2085
查看次数