博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# WinForm 多线程使用委托操作窗体控件
阅读量:7240 次
发布时间:2019-06-29

本文共 770 字,大约阅读时间需要 2 分钟。

1.需要通过委托操作的控件方法

public void InvokeMessage(string index, string result){    Label lbltip = new Label();    lbltip.BackColor = Color.Transparent;    lbltip.Name = "lbltip";    lbltip.Text = "暂无产品数据!";    lbltip.ForeColor = Color.White;    lbltip.Location = new Point(400, 25);    if (index == "1"){        this.gvBuildList.Controls.Add(lbltip);    }        this.Refresh();}

2.需要委托的方法注册给窗体委托

public void InvokeFrm(string index,string result){    this.Invoke(new InvokeMesage(InvokeMessage), new object[] { index,result });}

测试示例

public static int Main(){      Thread thread = new Thread(new ThreadStart(TestAlpha));    thread.IsBackground = true;    thread.Start();}   public void TestAlpha(){      int i = 0;    while (i < 3)      {        InvokeFrm("1", i++);    }      }

 

转载地址:http://wwfbm.baihongyu.com/

你可能感兴趣的文章
9.5 在 C# 中使用 F# 库
查看>>
2016第6周六
查看>>
Windows 下 绿化 Oracle
查看>>
利用京东云擎架设免费Wordpress 博客(git方式)
查看>>
Linux开发环境搭建与使用——ubuntu更新设置
查看>>
POJ 3740 Dancing Links
查看>>
iOS开发--使用NSMutableAttributedString 实现富文本
查看>>
十一、jdk命令之Jstatd命令(Java Statistics Monitoring Daemon)
查看>>
iOS开发小技巧--TableView Group样式中控制每个section之间的距离
查看>>
18.OGNL与ValueStack(VS)-值栈入门
查看>>
Linux进程间通信-匿名管道
查看>>
servlet过滤器配置白名单、黑名单
查看>>
linux下cmake编译安装、配置和卸载mysql
查看>>
HDU2639Bone Collector II[01背包第k优值]
查看>>
股指期货与融资融券做空机制有什么区别?
查看>>
Linux之ls命令
查看>>
twisted的defer模式和线程池
查看>>
.Net 配置文件——继承ConfigurationSection实现自定义处理类处理自定义配置节点
查看>>
Unity UI on hololens
查看>>
lsof -ntP -i:端口取出 动行程序的PID 然后xargs kill -9 这个进程
查看>>