void compareFiles(int progress) { if (bitmaps == null) return; comparisions = new Dictionary<ComparableBitmap, List<ComparableBitmap>>(); processed = new List<int>(); double p = 0; for (int i = 0; i < bitmaps.Count; i++) { if (bw.CancellationPending) break; if (!processed.Contains(i) && !comparisions.ContainsKey(bitmaps[i])) { comparisions.Add(bitmaps[i], new List<ComparableBitmap>()); processed.Add(i); ThreadQueue q = new ThreadQueue(bitmaps.Count / 10); Levenshtein alg = new Levenshtein(); for (int j = 0; j < bitmaps.Count; j++) { if (bw.CancellationPending) break; q.QueueUserWorkItem((WaitCallback)delegate(object a) { int r = (int)a; if (i != r && !processed.Contains(r)) { int k = alg.GetDistance<byte>(bitmaps[i], bitmaps[r]); if (k <= Settings.Default.SimilarityTreshold) { bitmaps[r].Similarity = k; comparisions[bitmaps[i]].Add(bitmaps[r]); processed.Add(r); if (OnNewDuplicateFound != null) { OnNewDuplicateFound(this, null); } } } }, j); bw.ReportProgress((int)(++p / (double)(bitmaps.Count * bitmaps.Count) * 100), string.Format(Resources.strProceessing, bitmaps[i].Path.Substring(bitmaps[i].Path.LastIndexOf('\\')+1))); } q.WaitAll(); } } }