void armorSearcher_SuitCreated(CompletedSuit obj) { BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); lock (lockObject) { // We don't accessorise suits that have less items than our best suit if (obj.Count < armorSearcherHighestItemCount) { return; } if (obj.Count > armorSearcherHighestItemCount) { armorSearcherHighestItemCount = obj.Count; // Disable previous accessory searchers that have a lower initial item count foreach (var kvp in accessorySearchers) { if (kvp.Value < armorSearcherHighestItemCount && kvp.Key != null && kvp.Key.Running) { kvp.Key.Stop(); } } } } Interlocked.Increment(ref accessoryThreadQueueCounter); ThreadPool.QueueUserWorkItem(delegate { AccessorySearcher accSearcher; lock (lockObject) { if (abortedSearch || obj.Count < armorSearcherHighestItemCount) { Interlocked.Decrement(ref accessoryThreadQueueCounter); ThreadFinished(); return; } Interlocked.Increment(ref accessoryThreadRunningCounter); accSearcher = new AccessorySearcher(new SearcherConfiguration(), searchItems, obj); accessorySearchers.TryAdd(accSearcher, obj.Count); } accSearcher.SuitCreated += new Action <CompletedSuit>(accSearcher_SuitCreated); accSearcher.Start(); accSearcher.SuitCreated -= new Action <CompletedSuit>(accSearcher_SuitCreated); Interlocked.Decrement(ref accessoryThreadRunningCounter); Interlocked.Decrement(ref accessoryThreadQueueCounter); ThreadFinished(); }); }
void armorSearcher_SuitCreated(CompletedSuit obj) { BeginInvoke((MethodInvoker)(() => AddCompletedSuitToTreeView(obj))); ThreadPool.QueueUserWorkItem(delegate { AccessorySearcher accSearcher = new AccessorySearcher(new SearcherConfiguration(), boundList, obj); accessorySearchers.Add(accSearcher); accSearcher.SuitCreated += new Action <CompletedSuit>(accSearcher_SuitCreated); accSearcher.Start(); accSearcher.SuitCreated -= new Action <CompletedSuit>(accSearcher_SuitCreated); }); }