首 页文章中心下载中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:开源盛世-源代码下载网 -> 文章中心 -> 其他编程 -> VC# 技术 -> 文章内容 退出登录 用户管理
栏目导航
· VC# 技术 · Delphi技术
· Java技术 · 通用算法
· 编程相关
热门文章
· Tab Control控件使用...
· 学生档案管理系统
· [图文] 排列组合公式
· UTF-8与GB2312之间的...
· DirectShow下载安装...
· Virtual PC 在PAE模...
· Windows2000终端服务...
· MapInfo上的GIS系统...
· Mapbasic参考手册索...
· MapX应用开发中文讲...
相关文章
C# 2.0 匿名方法与 Windows Forms 异步调用
作者:不详  来源:vscodes.com整理  发布时间:2006-6-20 10:21:24  发布人:Polaris

减小字体 增大字体

C# 2.0 匿名方法大大简化了 Windows Forms 异步调用的实现,我们再也不用手工定义异步委托或者包装类了。例如,在下面的代码示例中,Form1 有一个按钮控件和一个列表控件,在按钮控件的单击事件里,我们新建一个线程,在这个线程中向列表控件添加 10 个项目:

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;

...

private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(this.ThreadProc);
thread.Start();
}

private void ThreadProc()
{
for (int i = 0; i < 10; i++)
{
this.Invoke((MethodInvoker)delegate
{
this.listBox1.Items.Add("Item " + (i + 1).ToString());
});
}
}
}

End of《C# 2.0 匿名方法与 Windows Forms 异步调用》

[] [返回上一页] [打 印] [收 藏]
 
∷相关“C# 2.0 匿名方法与 Windows Forms 异步调用”文章评论∷
(评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 网站目录 鄂ICP备06007162
开源盛世 版权所有Copyright © 2003-2005 VSCodes.Com. All Rights Reserved.