



















using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WinAppAsync
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}private void btnLoad_Click(object sender, EventArgs e)
{
this.Text = "正在加载
";
//异步执行
LoadDataHandlerInstance = new LoadDataHandler(CreateData);
AsyncCallback callBackMethod = new AsyncCallback(CallBackLoad);
LoadDataHandlerInstance.BeginInvoke(callBackMethod, LoadDataHandlerInstance);
}public delegate DataTable LoadDataHandler();
public LoadDataHandler LoadDataHandlerInstance = null;
private DataTable CreateData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Address", typeof(string));for (int i = 0; i < 800000; i++)
{
DataRow row = dt.NewRow();
row["Id"] = i.ToString();
row["Name"] = "Name_" + i.ToString();
row["Address"] = "Address_" + i.ToString();
dt.Rows.Add(row);
}
return dt;
}
public void CallBackLoad(IAsyncResult result)
{
LoadDataHandler loadInstance = (LoadDataHandler)result.AsyncState;
DataTable dt = loadInstance.EndInvoke(result);
bindGridHandlerInstance
= new BindGridHandler(BindGrid);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。