Question : thread to simulate several executions

Hi i need call an store peocedure 30 times using thread to simulate several executions. I programming in .net 3.5

Answer : thread to simulate several executions

You could try something like:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
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();
}
Random Solutions  
 
programming4us programming4us