public Task<IPEndPoint> CreateLobby() {
            string id;
            int port;
            // Get lobby id & port.
            lock (_availablePorts) {
                if (_availablePorts.Count == 0)
                    return Task.FromResult<IPEndPoint>(null);
                port = _availablePorts.First();
                _availablePorts.RemoveAt(0);
            }
            lock (Lobbies) {
                do {
                    id = Guid.NewGuid().ToString("N").ToUpper().Substring(0, 6);
                } while (Lobbies.Exists(x => x.Id == id));
            }

        // Create lobby and start listening for clients
            LobbyInstance instance = new LobbyInstance(id, port);
            instance.ClientConnected += LobbyCreationCompleted;
            instance.ClientDisconnected += LobbySessionEnded;
            instance.Start();

            // Start client. TODO: Start in background
            ProcessStartInfo process = new ProcessStartInfo() {
                FileName = "Lobby",
                UseShellExecute = true, //TODO: Makes sure it uses a different console! (true)
                Arguments = $"-name {id} -port {port}",
                //CreateNoWindow = true
            };
            Process.Start(process);

            lock(Lobbies)
                Lobbies.Add(instance); // TODO: Not here
            // Wait for the client connection and return the IPendpoint of the client.
            return instance.LobbyInitialized.Task;
        }
 private void LobbySessionEnded(LobbyInstance sender) {
     Console.WriteLine($"Lobby instance with ID : <{sender.Id}> has shut down. Freeing up port.");
     lock (Lobbies)
         lock (_availablePorts) {
             _availablePorts.Add(sender.Port);
             Lobbies.Remove(sender);
             sender.Dispose();
         }
 }
 private void LobbyCreationCompleted(LobbyInstance sender, string clientId) {
     lock (Lobbies)
         Lobbies.Add(sender);
 }