Avoiding InvokeRequired
Just read a good article to do cross-thread calling in an easy and elegant way.
It is amazing for its simplicity and elegancy:
static class ControlExtensions
{
public static void InvokeOnOwnerThread<T>(this T control, Action<T> invoker) where T : Control
{
if (control.InvokeRequired)
control.Invoke(invoker, control);
else
invoker(control);
}
}
Only 10 lines to make the further calling a single line and extremely easy to read, very beautiful the way I like.
private void UpdateTextBoxFromSomeThread(string message)
{
textBox1.InvokeOnOwnerThread((txtBox) => txtBox.Text = message);
}
Would like to give all the credits to its author.
Original link: http://www.codeproject.com/Tips/374741/Avoiding-InvokeRequired
Avoiding InvokeRequired的更多相关文章
- 关于InvokeRequired与Invoke
from:http://www.th7.cn/Program/net/201306/140033.shtml Windows 窗体中的控件被绑定到特定的线程,不具备线程安全性.因此,如果从另一个线程调 ...
- InvokeRequired 线程间访问
zt: http://www.x2blog.cn/jinhong618/?tid=22389 问: f (this.InvokeRequired) { ...
- track message forwards, avoiding request loops, and identifying the protocol capabilities of all senders along the request/response chain
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html The TRACE method is used to invoke a remote, ...
- 读Avoiding the Disk Bottleneck in the Data Domain Deduplication File System
最近在思考和实践怎样应用重复数据删除技术到云存储服务中.找了些论文来读,其中<Avoiding the Disk Bottleneck in the Data Domain Deduplicat ...
- InvokeRequired和Invoke
C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它.此时它将会在内部调用ne ...
- Avoiding PostgreSQL database corruption
TL;DR: Don't ever set fsync=off, don't kill -9 the postmaster then deletepostmaster.pid, don't run P ...
- PLSQL_性能优化工具系列16_Best Practices: Proactively Avoiding Database
占位符 PLSQL_性能优化工具系列_Best Practices: Proactively Avoiding Database/Query Performance Issue
- 线程——委托InvokeRequired和Invoke
C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它.此时它将会在内部调用ne ...
- winform 开发之Control.InvokeRequired
Control.InvokeRequired 获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中. InvokeRequir ...
随机推荐
- Activity系列讲解---Activity运行时的屏幕方向,全屏,窗体模式的设置
Android内置了方向感应器的支持.Android会根据所处的方向自动在竖屏与横屏间切换.但是有的应用程序只能在横/竖屏时运行,比如某些游戏,此时我们要锁定该Activity运行时的屏幕方向,< ...
- 各种开源Android 系统定制
MIUI MIUI是由小米科技开发的Android装置系统.2016年2月24日,MIUI全球用户超过1.7亿.部分开源代码托管在GitHub 官网 国际网站 http://miuiandroid.c ...
- MyBK
- vmware 安装dos注意
vmware创建ms-dos虚拟机,安状DOS71.ISO. 新创建的机器,启动次序为Removable Devices/Hard Device/CD-ROM Device 新建的机器,第一次启动时, ...
- SQL添加维护 计划失败
在sql要求数据库每天自动备份这个是大家都会遇到的问题,我遇到了这个问题如图: 是因为这个服务组件没有安装
- Excel文件下载功能
HtmlTextWriter:能够帮助我们快速生成html语句. 下载功能实现代码 protected void Button1_Click(object sender, EventArgs e) { ...
- JSON对象格式美化
JSON.stringify(obh, null, "\t"); 这段代码就可以对某个js对象美化输出
- 【leetcode】Remove Nth Node From End of List
题目简述: Given a linked list, remove the nth node from the end of list and return its head. For example ...
- ASP.NET Boilerplate终于发布v1.0了
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ABP经过2年多的开发,终于发布第一个主要版本了,谨此提醒ABP的使用者. ASP.N ...
- 【iOS】Jenkins Gitlab持续集成打包平台搭建
Jenkins Gitlab持续集成打包平台搭建 SkySeraph July. 18th 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph个人站点: ...