protected void Button1_Click(object sender, EventArgs e)
{
List threads = new List(30);
// create 30 threads - but don't start them yet
for (int idx = 0; idx != 30; ++idx)
{
threads.Add(new Thread(new ParameterizedThreadStart(RunThread)));
}
// start all threads
for (int idx = 0; idx != 30; ++idx)
{
threads[idx].Start(idx + 1);
}
// wait for all threads to complete
foreach (Thread thread in threads)
{
thread.Join();
}
}
private void RunThread(object param)
{
int threadNo = int.Parse(param.ToString()); // this is the number of the thread - just in case you want it
string sConnStr = @"Data Source=(local);Initial Catalog=MyDatabase;UID=sa;pwd=KarenDej0";
SqlConnection cnBKTest = new SqlConnection(sConnStr);
SqlCommand cmdTest = new SqlCommand("MySP", cnBKTest);
cmdTest.CommandType = CommandType.StoredProcedure;
cmdTest.Parameters.Add(new SqlParameter("@prm1", SqlDbType.BigInt)).Value = 1;
cmdTest.Parameters.Add(new SqlParameter("@prm2", SqlDbType.BigInt)).Value = 2;
cnBKTest.Open();
cmdTest.ExecuteNonQuery();
cnBKTest.Close();
}
|