public async Task <GameSession> CreateGameSessionAsync( Player organizer, GameSessionConfiguration configuration) { try { await semaphoreSlim.WaitAsync(); var code = GenerateGameSessionCode(); var emptyDecks = Enumerable.Range(1, configuration.NumberOfDecks) .Select(n => new Deck(new Stack <Card>(), n % 2 == 0 ? DeckType.Ascending : DeckType.Descending)) .OrderBy(d => d.Type) .ToList(); var gameSession = new GameSession(organizer.PlayerId, code, new List <Player>() { organizer }, new List <Hand>(), configuration, deckService.GenerateDeck(configuration), emptyDecks, GameSessionStatus.Created, DateTime.Now, new List <int>(), new List <int>()); activeSessions.Add(code, gameSession); return(gameSession); } finally { semaphoreSlim.Release(); } }