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); }
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}"); }