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的更多相关文章

  1. 关于InvokeRequired与Invoke

    from:http://www.th7.cn/Program/net/201306/140033.shtml Windows 窗体中的控件被绑定到特定的线程,不具备线程安全性.因此,如果从另一个线程调 ...

  2. InvokeRequired 线程间访问

    zt: http://www.x2blog.cn/jinhong618/?tid=22389 问: f (this.InvokeRequired)            {               ...

  3. 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, ...

  4. 读Avoiding the Disk Bottleneck in the Data Domain Deduplication File System

    最近在思考和实践怎样应用重复数据删除技术到云存储服务中.找了些论文来读,其中<Avoiding the Disk Bottleneck in the Data Domain Deduplicat ...

  5. InvokeRequired和Invoke

    C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它.此时它将会在内部调用ne ...

  6. 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 ...

  7. PLSQL_性能优化工具系列16_Best Practices: Proactively Avoiding Database

    占位符 PLSQL_性能优化工具系列_Best Practices: Proactively Avoiding Database/Query Performance Issue

  8. 线程——委托InvokeRequired和Invoke

    C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它.此时它将会在内部调用ne ...

  9. winform 开发之Control.InvokeRequired

    Control.InvokeRequired 获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中. InvokeRequir ...

随机推荐

  1. js日期相关

    时间戳转正常日期时间 1469512964000 —> 2016/7/26 下午2:02 var getLocalTime = function(nS) { // 13位时间戳 return n ...

  2. Linux下安装流量监控工具iftop

    在Linux系统中,top命令可以查看系统资源包括内存,CPU占用信息,查看和探测网络状态可以使用netstat,nmap等工具,实时流量监控可以使用iftop,下面是在CentOS7系列系统上安装i ...

  3. 自定义TextView 调用ttf格式字体

    自定义TextView 调用ttf格式字体 1.<strong>将ttf格式文件存放在assets/fonts/下</strong> 注:PC系统字体存放在C:\Windows ...

  4. SemanticZoom配合GridView组件的使用关键点

    1,SemanticZoom 有两个重要属性 默认值ZoomedInView(不设置的话,默认显示,包括分类名和分类成员)和ZoomedOutView(这个是缩小后的目录,只要包括分类名,点击跳到对应 ...

  5. Linux 安装Mono环境 运行ASP.NET(二)

    一.安装libgdiplus     前面我们已经安装了apr.apr_util.pcre和httpd apache .现在我们来安装libgdiplus Libgdiplus是一个Mono库,用于对 ...

  6. mysql基准测试

    1. 及注册时有两种主要的策略:①正对整个系统的整体测试(集成式full-stack) ②单独测试mysql(但组件式基准测试single-component) 2.获取系统性能和状态(需要记录的数据 ...

  7. zookeeper3.3.6 伪分布式安装

    下载地址(http://zookeeper.apache.org/releases.html#download)   一:下载zookeeper的安装包,解压,进入到zk的目录文件,进入conf目录 ...

  8. Jmeter发送Java请求

    1.创建一个Java工程 2.把Jmeter的lib\ext目录下的ApacheJMeter_java.jar.ApacheJMeter_core.jar文件添加进该项目的Build Path 3.创 ...

  9. Optimal Flexible Architecture(最优灵活架构)

    来自:Oracle® Database Installation Guide 12_c_ Release 1 (12.1) for Linux Oracle base目录命名规范: /pm/s/u 例 ...

  10. python的Template

    Template模块,可以用来制作web页面的模板,非常的方便. Template属于string中的一个类,所以要使用的话要在头部引入: from string import Template 模板 ...