0
時做CreateHandle()//錯誤這是我的代碼值的Dispose()不能被稱爲同時使用線程
private void btnGenSumm_Click(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(loadSummSales));
Thread t2 = new Thread(new ThreadStart(showWaitMessage));
t1.Start();
t2.Start();
}
private void showWaitMessage()
{
label1.Text = "Processing please wait!";
}
private void loadSummSales()
{
try
{
sqlConn = new SqlConnection(MyClass.GlobalConn());
string cmdStr = "[dbo].[GetSummary]";
sqlConn.Open();
SqlCommand cmd = new SqlCommand(cmdStr, sqlConn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@piDateFrom", SqlDbType.Int).Value = Convert.ToInt32(FromD);
cmd.Parameters.Add("@piDateThru", SqlDbType.Int).Value = Convert.ToInt32(ToD);
System.Data.DataTable dT = new System.Data.DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dT);
cmd.ExecuteNonQuery();
dgSummSales.DataSource = dT;
dgSummSales.Columns["Branch"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgSummSales.Columns["Product Amt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dgSummSales.Columns["SERVICE Amt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
dgSummSales.Columns["Branch"].Width = 270;
dgSummSales.Columns["Product Amt"].Width = 98;
dgSummSales.Columns["SERVICE Amt"].Width = 103;
dgSummSales.Columns["Product Amt"].DefaultCellStyle.Format = "N2";
dgSummSales.Columns["SERVICE Amt"].DefaultCellStyle.Format = "N2";
dgSummSales.RowsDefaultCellStyle.BackColor = Color.White;
dgSummSales.AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine;
dgSummSales.Refresh();
label1.Text = "Sales as of " + dateTimePicker2.Value.ToString("d", System.Globalization.CultureInfo.GetCultureInfo("en-US"));
}
//我第一次點擊btnGenSumm按鈕,它沒有錯誤,但我的第二個嘗試,它會給出錯誤
值Dispose()
無法在做CreateHandle()
時調用。 Designer.cs
但是當我不使用線程時,我點擊btnGenSumm
按鈕多次就沒有錯誤。
我已經爲此嘗試了backgroundworker,但我得到了同樣的錯誤! –