public override TrackCollection Sort(BackgroundWorker backgroundWorker, TrackCollection trackCollection, TrackCollection fixedTracks) { var nbCollections = fixedTracks.Count; var resultCollection = new TrackCollection(); var collections = new List <TrackCollection>(); int numCollection = 0; fixedTracks.ForEach(delegate(Track track) { collections.Add(new TrackCollection()); int pos = trackCollection.IndexOf(track); if (pos != -1) { for (int i = 0; i < pos; i++) { collections[numCollection].Add(trackCollection[i]); } numCollection++; collections.Add(new TrackCollection()); collections[numCollection].Add(trackCollection[pos]); // add the fixed Track numCollection++; trackCollection.RemoveRange(0, pos + 1); } }); collections.Add(new TrackCollection()); for (int i = 0; i < trackCollection.Count; i++) { collections[numCollection].Add(trackCollection[i]); } numCollection++; trackCollection.Clear(); for (int i = 0; i < collections.Count; i++) { TrackCollection newCollection; newCollection = Sort(backgroundWorker, collections[i]); if (!newCollection.Equals(collections[i])) { var pos = collections.IndexOf(collections[i]); collections[pos] = newCollection; } } collections.ForEach(delegate(TrackCollection collection) { resultCollection.Concat(collection); }); return(resultCollection); }