View Single Post
  #1 (permalink)  
Old April 11th, 2006, 01:59 AM
vivekshah vivekshah is offline
Authorized User
 
Join Date: Apr 2006
Location: Jamnagar, Gujarat, India.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vivekshah Send a message via Yahoo to vivekshah
Default How do use Array with Threads



How can we use array of threads in c#.

Can we also create threads dynamically for an application having 20 threads...?

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Data.SqlClient;
namespace threaad
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Button btn1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here

            Thread t1 = new Thread( new ThreadStart( sayHello));
            Thread t2 = new Thread( new ThreadStart( sayHello));
            Thread t3 = new Thread( new ThreadStart( sayHello));
            Thread t4 = new Thread( new ThreadStart( sayHello));
            Thread t5 = new Thread( new ThreadStart( sayHello));
            Thread t6 = new Thread( new ThreadStart( sayHello));
            Thread t7 = new Thread( new ThreadStart( sayHello));
            Thread t8 = new Thread( new ThreadStart( sayHello));
            Thread t9 = new Thread( new ThreadStart( sayHello));
            Thread t10 = new Thread( new ThreadStart( sayHello));
            Thread t11 = new Thread( new ThreadStart( sayHello));
            Thread t12 = new Thread( new ThreadStart( sayHello));
            Thread t13 = new Thread( new ThreadStart( sayHello));
            Thread t14 = new Thread( new ThreadStart( sayHello));
            Thread t15 = new Thread( new ThreadStart( sayHello));
            Thread t16 = new Thread( new ThreadStart( sayHello));
            Thread t17 = new Thread( new ThreadStart( sayHello));
            Thread t18 = new Thread( new ThreadStart( sayHello));
            Thread t19 = new Thread( new ThreadStart( sayHello));
            Thread t20 = new Thread( new ThreadStart( sayHello));

// Thread []t = new Thread[20];
//
// Response.Write(t.ThreadState.ToString());
            for(int i=0;i<20;i++)
            {

               t[i].Start();
            }


            DateTime start = DateTime.Now;
            Response.Write("PROGRAM STARTED.AT.."+start.TimeOfDay );
            Response.Write("<br>");
//
// for( int i=1; i<=20; i++)
// {
// t(i).Start();
// }
// t1.Start();
// t2.Start();
// t3.Start();
// t4.Start();
// t5.Start();
// t6.Start();
// t7.Start();
// t8.Start();
// t9.Start();
// t10.Start();
// t11.Start();
// t12.Start();
// t13.Start();
// t14.Start();
// t15.Start();
// t16.Start();
// t17.Start();
// t18.Start();
// t19.Start();
// t20.Start();

            DateTime end = DateTime.Now;
            Response.Write("\nPROGRAM ENDED...at "+end.TimeOfDay);
            Response.Write("<br><br>");
            Response.Write("\nTime Taken : " + (end.Millisecond - start.Millisecond));


            btn1.Attributes.Add("onclick","javascript:clicked( )");
        }
        static void sayHello()
        {
            SqlConnection con = new SqlConnection("server=comp17;database=POS;user id=sa;password=cmie");
            //string qry = "SELECT * FROM PRODUCTS WHERE MFG_NAME LIKE ' "+ condition + "%' ";
            string qry = "SELECT TOP 10000 * FROM PRODUCTS ";
            SqlCommand myCmd = new SqlCommand(qry,con);
            DataSet ds = new DataSet();
            myCmd.Connection.Open();
            myCmd.ExecuteNonQuery();

            myCmd.Connection.Close();

        }












Vivek Shah
__________________
Vivek Shah
Reply With Quote