I have an array of custom objects named AnalysisResult
. The array can contain hundreds of thousands of objects; and, occasionally I need only the Distinct()
elements of that array. So, I wrote a item comparer class called AnalysisResultDistinctItemComparer
and do my call like this:
public static AnalysisResult[] GetDistinct(AnalysisResult[] results)
{
return results.Distinct(new AnalysisResultDistinctItemComparer()).ToArray();
}
My problem here is that this call can take a LONG time (on the order of minutes) when the array is particularly big (greater than 200,000 objects).
I currently call that method in a background worker and display a spinning gif to alert the user that the method is being performed and that the application has not frozen. This is all fine and well but it does not give the user any indication of the current progress.
I really need to be able to indicate to the user the current progress of this action; but, I have been unable to come up with a good approach. I was playing with doing something like this:
public static AnalysisResult[] GetDistinct(AnalysisResult[] results)
{
var query = results.Distinct(new AnalysisResultDistinctItemComparer());
List<AnalysisResult> retVal = new List<AnalysisResult>();
foreach(AnalysisResult ar in query)
{
// Show progress here
retVal.Add(ar);
}
return retVal.ToArray();
}
But the problem is that I have no way of knowing what my actual progress is. Thoughts? Suggestions?