With the code below, how will I know if my thread is already done doing tasks? My purpose is to kill that thread in order to free memory. Or how should I do it?
private delegate void DelegateSetProperties(DataTable dataSource, string valueMember, string displayMember);
Thread thread1;
DelegateSetProperties delegateSetProperties;
private void Form1_Load(object sender, EventArgs e)
{
delegateSetProperties = new DelegateSetProperties(SetProperties);
thread1 = new Thread(new ThreadStart(InitValues));
thread1.IsBackground = true;
thread1.Start();
// should I abort thread1 here? if I abort it, does it frees the memory occupied by thread1?
}
private void SetProperties(DataTable dataSource, string valueMember, string displayMember)
{
comboBox1.DataSource = dataSource;
comboBox1.ValueMember = valueMember;
comboBox1.DisplayMember = displayMember;
comboBox1.SelectedIndex = 0;
}
void InitValues()
{
var dt = new DataTable
{
TableName = "CATEGORY",
Columns = {
{"CategoryCode", typeof(string)},
{"Name", typeof(string)},
}
};
dt.Rows.Add("C1", "Category1");
dt.Rows.Add("C2", "Category2");
dt.Rows.Add("C3", "Category3");
// and so on...
comboBox1.Invoke(delegateSetProperties, new object[] { dt, "CategoryCode", "Name"
});
}