protected override ITcpServerSocketModel RunInternal(ITcpServerSocketModel obj0) { var clientsToBeDisconnected = obj0.LocalChannels.Take(ClientCount).ToList(); var disconnectTasks = new List <Task>(); foreach (var client in clientsToBeDisconnected) { disconnectTasks.Add(client.DisconnectAsync()); } if (Task.WaitAll(disconnectTasks.ToArray(), TimeSpan.FromSeconds(ClientCount))) { throw new TimeoutException( $"Waited {ClientCount} seconds to disconnect {ClientCount} clients from {obj0.BoundAddress}, but the operation timed out."); } foreach (var client in clientsToBeDisconnected) { obj0 = obj0.RemoveClient((IPEndPoint)client.LocalAddress).RemoveLocalChannel(client); } return(obj0); }