Service Fabric Actor方法调用不返回值

时间:2017-05-11 18:34:54

标签: c# azure return-value actor azure-service-fabric

我有一个简单的C#控制台应用程序,它与Service Fabric actor交互并通过actor事件接收信息。

问题是我在客户端EventHandler上调用了一个返回int[]值的actor方法,即使该方法在actor上正确执行(ActorEventSource消息调试),客户端也没有收到返回值而没有退出方法任何错误异常。

这是客户的方案

    class LobbyEventsHandler : IGameLobbyEvents
    {
        private GameManager p_gameManager;

        public LobbyEventsHandler(GameManager i_gameManager)
        {
            p_gameManager = i_gameManager;
        }

        public void GameStart()
        {
            Console.WriteLine("Game starting");
            p_gameManager.StartGame();
        }
    }

    class GameManager
    {
        public int state;
        private int[] p_playerPosReal;
        private IGameManagerActor p_actor;
        public string playerName;

        public IGameManagerActor actor
        {
            set
            {
                p_actor = value;
            }
        }

        public GameManager()
        {
            state = 1;
        }

        public void SubscribeToLobbyEvents()
        {
            p_actor.SubscribeAsync<IGameLobbyEvents>(new LobbyEventsHandler(this));
        }

        public void StartGame()
        {
            state = 2;
            Console.WriteLine("Getting position");
            p_playerPosReal = p_actor.GetPlayerPos(playerName).Result;
            Console.WriteLine("Position gotten");
        }
    }

   class Program
    {
        static void Main(string[] args)
        {
            bool exit = false;
            GameManager gameManager = new GameManager();
            while (!exit)
            {
                gameManager.actor = ActorProxy.Create<IGameManagerActor>(new ActorId("Manager"), APP_NAME);
                gameManager.SubscribeToLobbyEvents();
                Console.ReadKey();
            }
        }
    }

方法GetPlayerPos必须返回Task<int[]>值,但它不起作用,演员完成执行并且客户端没有抓住它

我该怎么办?

0 个答案:

没有答案