asp.net开启多线程异步处理

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    Thread categoryThread = new Thread(new ThreadStart(BindCategory));
                    Thread newsThread = new Thread(new ThreadStart(BindNews));


                    categoryThread.Start();
                    newsThread.Start();


                    categoryThread.Join();
                    newsThread.Join();
                }
                catch (Exception ex)
                {
                    Response.Write(ex);
                }
            }
        }
  void BindCategory()
        {


            SqlConnection conn = ReturnSqlconn();
            SqlCommand comm = new SqlCommand("select * from  [dbo].[Channel_List]", conn);
            conn.Open();
            SqlDataReader sdr = comm.ExecuteReader();


            GridView1.DataSource = sdr;
            GridView1.DataBind();
        }
        void BindNews()
        {
            SqlConnection conn = ReturnSqlconn();
            SqlCommand comm = new SqlCommand("select * from  [dbo].[Channel_Type]", conn);
            conn.Open();
            SqlDataReader sdr = comm.ExecuteReader();


            GridView2.DataSource = sdr;
            GridView2.DataBind();


        }
 public SqlConnection ReturnSqlconn()
        { 
           string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
           SqlConnection cn = new SqlConnection(connectionString);
           return cn;
        }

 

posted on 2018-07-18 15:17  哦呵呵G  阅读(321)  评论(0编辑  收藏  举报

导航