private async Task <IList <IHubConnectionAdapter> > RecreateBrokenConnections( IList <IHubConnectionAdapter> connections, IList <int> connectionIndex, string urls, string transportTypeString, string protocolString, int closeTimeout, ClientType clientType) { // Filter broken connections and local index var packages = (from i in Enumerable.Range(0, connections.Count) where connections[i].GetStat() == SignalREnums.ConnectionInternalStat.Stopped select new { Connection = connections[i], LocalIndex = i, GlobalIndex = connectionIndex[i] }).ToList(); // Destroy broken connections foreach (var package in packages) { await package.Connection.StopAsync(); await package.Connection.DisposeAsync(); } var globalConnIndex = (from pkg in packages select pkg.GlobalIndex).ToList(); // Re-create connections var newConnections = SignalRUtils.CreateClientConnection( transportTypeString, protocolString, urls, globalConnIndex, clientType); // Setup connection drop handler SignalRUtils.SetConnectionOnClose(newConnections); // Map new connections to orignal connection list for (var i = 0; i < newConnections.Count; i++) { connections[packages[i].LocalIndex] = newConnections[i]; } return(newConnections); }