zoukankan      html  css  js  c++  java
  • Asp.Net多线程用法1

    Asp.Net多线程简单用法

    一个web页面 default.aspx 里面有两个控件GridView1,GridView2,通过两个线程分别加载绑定数据。

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    Thread thead1 = new Thread(new ThreadStart(BindPeople));//定义线程
                    Thread thead2 = new Thread(new ThreadStart(BindNews));
    
                    thead1.Start(); //启动线程
                    thead2.Start();
    
                    thead1.Join();  //大概就是和UI线程同步的意思
                    thead2.Join();  
                }
                catch (Exception ex)
                {
                    Response.Write(ex);
                }
            }
        }
        /// <summary>
        /// 绑定用户
        /// </summary>
        private void BindPeople()
        {
            DataTable dt = DBHelper.GetDataTable("select * from people");
            GridView1.DataSource = sdr;
            GridView1.DataBind();
        }
        /// <summary>
        /// 绑定新闻
        /// </summary>
        private void BindNews()
        {
            DataTable dt = DBHelper.GetDataTable("select * from news");
            GridView2.DataSource = sdr;
            GridView2.DataBind();
        }
  • 相关阅读:
    QQ空间鼠标代码
    QQ空间Flash
    QQ播放器代码
    QQ空间鼠标代码
    QQ空间Flash
    QQ空间Flash
    第二届“携进杯”师生羽毛球联谊赛
    DataView对象
    数据控件DataGrid数据控件
    数据控件Repeater数据控件
  • 原文地址:https://www.cnblogs.com/webapi/p/5669094.html
Copyright © 2011-2022 走看看