//void ClientLoopThread(object oid)
        //{
        //    var id = (int)oid;

        //    Logger.Warn("Now Start Client: {0}", id);
        //    // Login
        //    string host;
        //    LoginResponse loginRes;
        //    using (var client = new GateClient("127.0.0.1", 14002))
        //    {
        //        var t = client.Login(id);
        //        t.Wait();
        //        loginRes = t.Result;
        //        if (loginRes == null)
        //            return;

        //        if (loginRes.Id != id)
        //            throw new Exception("Error id");
        //        host = loginRes.GameServerHost;
        //        if (host == "*")
        //        {
        //            host = "127.0.0.1";
        //        }
        //    }

        //    // Connect game server
        //    var gameClient = new PlayerHandlerClient(host, loginRes.GameServerPort, loginRes.SubcribePort);
        //    var sessionToken = gameClient.SessionToken;
        //    if (string.IsNullOrEmpty(sessionToken))
        //    {
        //        gameClient.HandshakeAsync().Wait();
        //        sessionToken = gameClient.SessionToken;

        //        if (string.IsNullOrEmpty(sessionToken))
        //            throw new Exception("No SessionToken Error!");
        //    }
        //    // 操作100次后结束客户端
        //    for (var i = 0; i < int.MaxValue; i++)
        //    {
        //        var rand = new Random();
        //        var randLevelId = rand.Next(1, 100000);
        //        gameClient.EnterLevel(sessionToken, randLevelId).Wait();

        //        _callCount++;

        //        // 5s in level
        //        //await Task.Delay(1);
        //        Thread.Sleep(1);
        //        gameClient.FinishLevel(new PlayerHandlerClient.FinishLevelRequest()
        //        {
        //            SessionToken = sessionToken,
        //            LevelTypeId = randLevelId,
        //            IsSuccess = true
        //        }).Wait();

        //        //var co2 = Coroutine2.Start<bool>(gameClient.FinishLevel,
        //        //        );

        //        //while (!co2.IsFinished)
        //        //    await Task.Delay(0);

        //        _callCount++;
        //    }
        //    // Logout, Append player result
        //    Logger.Warn("Now End Client.................. {0}", id);

        //}

        private async void TestLoopAsync(int id)
        {
            Logger.Warn("Now Start Client: {0}", id);
            // Login
            string        host;
            LoginResponse loginRes;

            using (var client = new GateClient("127.0.0.1", 14002))
            {
                while (true)
                {
                    loginRes = await client.Login(id);

                    if (loginRes == null)
                    {
                        return;
                    }

                    if (loginRes.Id != id)
                    {
                        throw new Exception("Error id");
                    }
                    host = loginRes.GameServerHost;
                    if (host == "*")
                    {
                        host = "127.0.0.1";
                    }
                    _callCount++;
                }
            }
        }
        //void ClientLoopThread(object oid)
        //{
        //    var id = (int)oid;

        //    Logger.Warn("Now Start Client: {0}", id);
        //    // Login
        //    string host;
        //    LoginResponse loginRes;
        //    using (var client = new GateClient("127.0.0.1", 14002))
        //    {
        //        var t = client.Login(id);
        //        t.Wait();
        //        loginRes = t.Result;
        //        if (loginRes == null)
        //            return;

        //        if (loginRes.Id != id)
        //            throw new Exception("Error id");
        //        host = loginRes.GameServerHost;
        //        if (host == "*")
        //        {
        //            host = "127.0.0.1";
        //        }
        //    }

        //    // Connect game server
        //    var gameClient = new PlayerHandlerClient(host, loginRes.GameServerPort, loginRes.SubcribePort);
        //    var sessionToken = gameClient.SessionToken;
        //    if (string.IsNullOrEmpty(sessionToken))
        //    {
        //        gameClient.HandshakeAsync().Wait();
        //        sessionToken = gameClient.SessionToken;

        //        if (string.IsNullOrEmpty(sessionToken))
        //            throw new Exception("No SessionToken Error!");
        //    }
        //    // 操作100次后结束客户端
        //    for (var i = 0; i < int.MaxValue; i++)
        //    {
        //        var rand = new Random();
        //        var randLevelId = rand.Next(1, 100000);
        //        gameClient.EnterLevel(sessionToken, randLevelId).Wait();

        //        _callCount++;

        //        // 5s in level 
        //        //await Task.Delay(1);
        //        Thread.Sleep(1);
        //        gameClient.FinishLevel(new PlayerHandlerClient.FinishLevelRequest()
        //        {
        //            SessionToken = sessionToken,
        //            LevelTypeId = randLevelId,
        //            IsSuccess = true
        //        }).Wait();

        //        //var co2 = Coroutine2.Start<bool>(gameClient.FinishLevel,
        //        //        );

        //        //while (!co2.IsFinished)
        //        //    await Task.Delay(0);

        //        _callCount++;
        //    }
        //    // Logout, Append player result
        //    Logger.Warn("Now End Client.................. {0}", id);

        //}

        private async void TestLoopAsync(int id)
        {
            Logger.Warn("Now Start Client: {0}", id);
            // Login
            string host;
            LoginResponse loginRes;
            using (var client = new GateClient("127.0.0.1", 14002))
            {
                while (true)
                {
                    loginRes = await client.Login(id);
                    if (loginRes == null)
                        return;

                    if (loginRes.Id != id)
                        throw new Exception("Error id");
                    host = loginRes.GameServerHost;
                    if (host == "*")
                    {
                        host = "127.0.0.1";
                    }
                    _callCount++;
                }

            }
        }