I've got a program that does a search using directory services, and the problem i'm having is returning the results. I moved the search to a background thread (using System.Threading.Thread) so that it can be cancelled, gui remains responsive, etc.
I've defined an event called itemFound that gets fired back to the main form each time this search turns up some results.
The problem i'm having occurs when i want to add that found item to an ArrayList stored in the main form. Later, when I try to sort that array, i get an InvalidOperationException - At least one member must implement IComparable error.
I think the problem lies in that i'm not invoking the methods of the main form correctly... stop me if you think something else might be the problem.
I don't know of a way to invoke a method that takes parameters... and i think that could help also if someone knows how to do that.
Here's the code that gets executed when the search thread raises an itemFound event. This code lies in my main form.
and that of course invokes this method:
Any thoughts? Thanks in advance... i know that was kind of a long read!!!
I've defined an event called itemFound that gets fired back to the main form each time this search turns up some results.
The problem i'm having occurs when i want to add that found item to an ArrayList stored in the main form. Later, when I try to sort that array, i get an InvalidOperationException - At least one member must implement IComparable error.
I think the problem lies in that i'm not invoking the methods of the main form correctly... stop me if you think something else might be the problem.
I don't know of a way to invoke a method that takes parameters... and i think that could help also if someone knows how to do that.
Here's the code that gets executed when the search thread raises an itemFound event. This code lies in my main form.
Code:
private String itemString = "";
private void itemFound(String s)
{
itemString = s;
this.Invoke(new MethodInvoker(this.doAddItem));
}
and that of course invokes this method:
Code:
private void doAddItem()
{
if (itemString != "User not found")
{
parsedItem = parseResults(itemString);
items.Add(parsedItem);
//this.Invoke(new MethodInvoker(this.addItem));
listBox1.Items.Add(parsedItem[0] + " - " + parsedItem[1]);
//this.Invoke(new MethodInvoker(this.lstAddItem));
if (items.Count == 1)
lblResults.Text = "1 Item Found";
else
lblResults.Text = items.Count.ToString() + " Items Found";
}
else
lblResults.Text = "0 Items Found";
}
Any thoughts? Thanks in advance... i know that was kind of a long read!!!