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. [mark] 使用Sublime Text 2时如何将Tab配置为4个空格

    在Mac OS X系统下,Sublime Text是一款比较赞的编辑器. 作为空格党的自觉,今天mark一下使用Sublime Text 2时如何将Tab配置为4个空格: 方法来自以下两个链接: ht ...

  2. 关于清除arp 缓存的那点事儿

    在Linux下,清除arp缓存表,例如: arp -d 10.0.3.6 我们可以用上面这条命令清除某一条记录,也可以用 arp -n |awk '/^[1-9]/{print "arp - ...

  3. 设计模式--享元模式Flyweight(结构型)

    一.享元模式 在一个系统中如果有多个相同的对象,这些对象有部分状态是可以共享的,我们运用共享技术就能有效地支持大量细粒度的对象. 二.例子 举个围棋的例子,围棋的棋盘共有361格,即可放361个棋子. ...

  4. js_闭包

    先从闭包特点解释,应该更好理解.闭包的两个特点:1.作为一个函数变量的一个引用 - 当函数返回时,其处于激活状态.2.一个闭包就是当一个函数返回时,一个没有释放资源的栈区.其实上面两点可以合成一点,就 ...

  5. 419. Battleships in a Board

    https://leetcode.com/problems/battleships-in-a-board/ 给定一个N×N的棋盘,有任意数量的1×N或N×1大小的"船",注意船船之 ...

  6. go:多核并行化问题

    分别用串行和并行实现了一个NUM次加法的程序,代码如下: package main import ( "fmt" //"runtime" //执行并行段时需要引 ...

  7. SQL Server删除重复行的6个方法

    SQL Server删除重复行是我们最常见的操作之一,下面就为您介绍六种适合不同情况的SQL Server删除重复行的方法,供您参考. 1.如果有ID字段,就是具有唯一性的字段 delect   ta ...

  8. 良心版Dolby Home Theater v4.1安装教程

    感(pi)谢(pan)一下两个教程: 文库文章链接:http://wenku.baidu.com/link?url=beBg_apvCuY3xiCXk4zl65Q7AmeCjoDGMol03K0xhk ...

  9. ubuntu selinux

    apt install selinux-utils apt install policycoreutils https://zhidao.baidu.com/question/917938889387 ...

  10. 自用VS Code 上的Markdown 编辑器css

    目标效果如下: 主题使用:Markdown Yellow 主题[https://marketplace.visualstudio.com/items?itemName=ms-vscode.Theme- ...