您的位置:首页 > 编程语言 > ASP

Asp.Net多线程用法1

2016-03-24 15:18 471 查看

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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: