码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-07-18 16:57:21      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:new   nta   conf   read   ack   bsp   try   idv   select   

 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;
        }

 

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

标签:new   nta   conf   read   ack   bsp   try   idv   select   

原文地址:https://www.cnblogs.com/gsh0921/p/9329327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!