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. SQL Server子查询实例

    例子一 SELECT COUNT(*) FROM ( SELECT [PersonID] FROM [tbiz_AssScore] GROUP BY PersonID ) M 语法说明: 1).FRO ...

  2. 浅谈HTTP中Get与Post的区别

    引用自:http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET ...

  3. Python 开源网上商城项目

    django-oscar  https://github.com/django-oscar/django-oscar#screenshots django-shop  https://github.c ...

  4. windows耳机没有声音

    问题描述: 扬声器有声音,耳机没有声音,重装了驱动也没有用,系统配置.耳机也没有问题,具体原因我不太清楚,参考网址:http://forum.ubuntu.org.cn/viewtopic.php?f ...

  5. angular-route 和soket注意细节点

    route run 文件是第一个位置,之后才配置路由哪些,代码: angular.module('technodeApp',['ngRoute']).run(function($window,$roo ...

  6. CentOS7 cacti 安装

    首先centos7 web环境的安装这里就不说了.安装cacti,首先得web环境配置好 其次添加两个用户,一个是cacti用于操作mysql的 cactimysql  一个是cacti操作Linux ...

  7. 联想笔记本如何开启笔记本的VT-x虚拟化技术功能

    虚拟化技术支持,需几个方面的条件支持:芯片组自身支持.BIOS提供支持.处理器自身支持.操作系统支持. 操作系统方面,主流操作系统均支持VMM管理,因此无需考虑. 而芯片组方面,从Intel 945( ...

  8. postgresql 常用数据库命令

    连接数据库, 默认的用户和数据库是postgrespsql -U user -d dbname 切换数据库,相当于MySQL的use dbname\c dbname列举数据库,相当于mysql的sho ...

  9. linux进程通信

    e14: 进程间通信(进程之间发送/接收字符串/结构体): 传统的通信方式: 管道(有名管道 fifo,无名管道 pipe) 信号 signal System V(基于IPC的对象):         ...

  10. android中接口和抽象类的区别

    最近发现很多基础有点生疏了,特地写一点博客来巩固一下.今天主要来谈谈接口和抽象类的区别,我们在项目的很多地方都会用到接口或者抽象类,但是它们之间的一些区别和相同点不知道大家有没有注意到,还有就是,什么 ...