I am in need to track when all threads I have created have finished. I have searched and tried example after example over the past two days to no avail and was wondering if I could get some assistance. Thank you in advance.
My form runs a series of queries on button click based off of what check boxes the user checks. Each of these check boxes has it's own thread that gets created on the button click. Datagridviews and graphs are populated based on the checkbox selections.
Here's the button click and two of the threads being created. I disabled the controls on the form while the queries run because I didn't want the user to be able to send another query request while the other was processing.
Is there a method I could make that would constantly check that my threads have completed and would then re-enable my form controls?
public void btn_runGRM_Click(object sender, EventArgs e)
{
this.btn_runGRM.Enabled = false;
this.checkBox_Assgn.Enabled = false;
this.checkBox_Avail.Enabled = false;
this.checkBox_RFI.Enabled = false;
this.checkBox_Census.Enabled = false;
this.ChartDGV.Visible = true;
if (checkBox_Assgn.Checked)
{
AssignmentDGV.DataSource = null;
AssignmentDGV.Rows.Clear();
AssignmentDGV.Refresh();
Assgn_timer = new System.Windows.Forms.Timer();
Assgn_timer.Interval = (1000);
Assgn_timer.Tick += new EventHandler(Assgn_timer_Tick);
Assgn_sw = new System.Diagnostics.Stopwatch();
Assgn_timer.Start();
Assgn_sw.Start();
ThreadStart childref1 = new ThreadStart(CallToChildthread1);
Thread childThread1 = new Thread(childref1);
childThread1.Start();
}
if (checkBox_Census.Checked)
{
CensusDGV.DataSource = null;
CensusDGV.Rows.Clear();
CensusDGV.Refresh();
Census_timer = new System.Windows.Forms.Timer();
Census_timer.Interval = (1000);
Census_timer.Tick += new EventHandler(Census_timer_Tick);
Census_sw = new System.Diagnostics.Stopwatch();
Census_timer.Start();
Census_sw.Start();
ThreadStart childref2 = new ThreadStart(CallToChildthread2);
Thread childThread2 = new Thread(childref2);
childThread2.Start();
}
}
Here is a bit of code from one of the child threads
public void CallToChildthread1()
{
string oradb = "......";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
OracleParameter parm = new OracleParameter();
parm.OracleDbType = OracleDbType.Varchar2;
if (textBox1.Text == "")
{
parm.Value = ' ';
}
else
{
parm.Value = textBox1.Text;
}
cmd = new OracleCommand();
cmd.Connection = conn;
cmd.Parameters.Add(parm);
cmd.CommandText = "SELECT .......";
}