Exemplo n.º 1
0
        public virtual async Task Run()
        {
            const int PING_COUNT = 100;

            var duration = await StopWatchUtils.MeasureActionTime(async() =>
            {
                var firstPlayer  = m_player1.Ping(PING_COUNT, m_player2, GAME_1_NAME);
                var secondPlayer = m_player2.Ping(PING_COUNT, m_player1, GAME_2_NAME);
                await Task.WhenAll(firstPlayer, secondPlayer);
            });

            Console.WriteLine(RUN_DURATION_MESSAGE_FORMAT, duration.TotalMilliseconds);
        }
Exemplo n.º 2
0
        public async Task Ping(int pingCount, IAsyncPlayer secondPlayer, string gameName)
        {
            var currentGameName = gameName ?? Empty;

            Console.WriteLine($"{m_name} Ping number: {pingCount} tid: {Thread.CurrentThread.ManagedThreadId} game: {currentGameName}");

            if (pingCount > 0)
            {
                await secondPlayer.Ping(pingCount - 1, this, gameName);

                m_pingCounter++;
            }
            Console.WriteLine($"{m_name} Ping total: {m_pingCounter} tid: {Thread.CurrentThread.ManagedThreadId}, game: {currentGameName}");
        }