Take a look at my code.
Thread[] connect_thread;
public void thread_runned()
{
connect_thread = new Thread[dataGridView1.SelectedRows.Count];
for (int index = 0; index < dataGridView1.SelectedRows.Count; index++)
{
connect_thread[index] = new Thread(new ThreadStart(connect));
connect_thread[index].Start();
}
}
public void connect()
{
//performance code here
}
public void ButtonClick1()
{
//User select rows 0-4
thread_runned();
}
public void ButtonClick2()
{
//User select rows 5-9
thread_runned();
}
According to the code above, when I run it, and click on ButtonClick1
and ButtonClick2
, it returns two different connect_thread
s (see this debug for more detail.)
//Debug when ButtonClick1 is running
connect_thread = array(
[0] = System.Threading.Thread
[1] = System.Threading.Thread
[2] = System.Threading.Thread
[3] = System.Threading.Thread
)
//Debug when ButtonClick2 is running
connect_thread = Error: Index was outside the bounds of the array.
Now, I want to add a new thread item into this thread array, but the indeces must continue like the old thread items (i.e, the next indeces will be [4]
, [5]
, [6]
, etc.)
I'm not worrying about this error:
//Debug when ButtonClick2 is running
connect_thread = Error: Index was outside the bounds of the array.
because I can create a list of threads using dataGridView1.Rows.Count
, and it will work fine. However, I'm looking to do it the other way other because when the user adds more data into dataGridView
, the index will be wrong again.
How can I append new threads to the end of my thread array while preserving indeces?