【问题标题】:Running delayed work on Azure Mobile Service在 Azure 移动服务上运行延迟工作
【发布时间】:2015-01-21 22:47:09
【问题描述】:

我正在尝试在 Azure 上构建游戏服务器。我有一个控制器,它应该在 30 秒后触发游戏中的空袭。

我是 C# 和 Azure 的新手。这是我糟糕的尝试:

public class CallAirstrikeController : ApiController
{

    public ApiServices Services { get; set; }

    public Whatever Post(Coordinate coordinate)
    {
        CallAirstrike(coordinate); // Don't wait
        // Do other things...
        return whatever;
    }

    private async Task CallAirstrike(Coordinate coordinate)
    {
        await Task.Delay(30000); // Wait for it...
        CreateExplosion(coordinate); // Boom
    }

}

控制器按预期立即返回,但看起来不像在任何时候调用CreateExplosion

我做错了什么?

【问题讨论】:

    标签: c# asp.net azure async-await


    【解决方案1】:

    找到了解决办法,在这里:

    Task.Run( async () => await CallAirstrike(coordinate) );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 2016-05-05
      相关资源
      最近更新 更多