I'm trying to search in array variable have big data using combobox autocomplete.
And this is my work:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread thread1;
long test1 = 0;
string randName;
String[] ComboboxValue = new String[20001];
private void button1_Click(object sender, EventArgs e)
{
thread1 = new Thread(add_combo_1);
thread1.Start();
}
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
private void add_combo_1()
{
while (test1++ < 20000)
{
randName = RandomString(1000);
this.Invoke((MethodInvoker)delegate () {
//comboBox1.Items.Add(randName.ToString());
ComboboxValue[test1] = randName.ToString();
comboBox1.AutoCompleteCustomSource.Add(ComboboxValue[test1]);
});
}
}
}
This what i use setting of combobox:
I think crash happened when i searching and the program still loading data to array.
So any one have a solution?
you have to let the program finish going through the while loop that you set unless you insert a break;
inside with or without a IF statement inside the loop