Delegate.Invoke

Delegate.Invoke is used to execute a delegate on the current thread. A delegate is just a reference to a function or method, and Delegate.Invoke is the mechanism to call this function or method (similar to a normal function call).

Delegate.BeginInvoke

Delegate.BeginInvoke is used to execute a delegate asynchronously, that is, on a separate thread. That means that you can start an operation which won't block your current thread, it will be executed on it's own thread. Delegate.BeginInvoke the operation will be performed "in the background", that is, on a separate thread. Note that you need to call EndInvoke at some time after BeginInvoke to avoid resource leaks.

As its a seperate thread you must not update any property or call any method of a Windows Forms user that potentially update the UI. If you want to update a progress bar, fill a list, or do somehting similar while the operation is performed, you have to use a different mechanism: Control.Invoke or Control.BeginInvoke.

Control.Invoke

Control.Invoke is used to execute a delegate on the UI thread of that control. If you have a delegate which updates the user interface, you can call Control.Invoke from your other thread to execute the update operation on the UI thread.

Control.BeginInvoke

Control.BeginInvoke does the same, but in an asynchronous way. This means that, while Control.Invoke waits until the UI thread has finished executing the delegate, Control.BeginInvoke returns immediately.

Notes to remember:

Control.Invoke, Control.BeginInvoke, and Control.InvokeRequired are exceptions and can use these from other threads than the UI thread.

总的来说就是Delegate.BeginInvoke()是从线程池中取出一个新线程来执行,Delegate.Invoke()和普通调用效果上没什么区别。

而Control.BeginInvoke()和Control.Invoke()都是返回到UI线程上执行的。

C# 异步机制的更多相关文章

  1. 结合源码看nginx-1.4.0之nginx异步机制详解

    目录 0. 摘要 1. nginx异步设计思想 2. nginx异步设计数据结构 3. nginx异步机制源码解析 4. 一个简单的应用异步例子 5. 小结 6. 参考源码

  2. JavaScript的异步机制

    我们经常说JS是单线程的,比如node.js研讨会上大家都说JS的特色之一是单线程的,这样使JS更简单明了,可是大家真的理解所谓JS的单线程机制吗?单线程时,基于事件的异步机制又该当如何 1 先看下两 ...

  3. JavaScript单线程和异步机制

    随着对JavaScript学习的深入和实践经验的积累,一些原理和底层的东西也开始逐渐了解.早先也看过一些关于js单线程和事件循环的文章,不过当时看的似懂非懂,只留了一个大概的印象:浏览器中的js程序时 ...

  4. 深入理解Spring的异步机制

    一.Spring中实现异步执行 在这里我先以事件的机制举例,注意默认情况下事件的发布与监听都是同步执行的.那么我们来看一看基于异步事件的例子该怎么写 首先还是定义事件: package com.bdq ...

  5. [转]JavaScript异步机制详解

    原文: https://www.jianshu.com/p/4ea4ee713ead --------------------------------------------------------- ...

  6. Windows store app[Part 4]:深入WinRT的异步机制

    接上篇Windows store app[Part 3]:认识WinRT的异步机制 WinRT异步机制回顾: IAsyncInfo接口:WinRT下异步功能的核心,该接口提供所有异步操作的基本功能,如 ...

  7. Windows store app[Part 3]:认识WinRT的异步机制

    WinRT异步机制的诞生背景 当编写一个触控应用程序时,执行一个耗时函数,并通知UI更新,我们希望所有的交互过程都可以做出快速的反应.流畅的操作感变的十分重要. 在连接外部程序接口获取数据,操作本地数 ...

  8. 前端知识点回顾之重点篇——JavaScript异步机制

    JavaScript异步机制 来源:https://www.cnblogs.com/zhaodongyu/p/3922961.html JavaScript是单线程异步执行的,单线程意味着代码在任务队 ...

  9. Js异步机制的实现

    Js异步机制 JavaScript是一门单线程语言,所谓单线程,就是指一次只能完成一件任务,如果有多个任务,就必须排队,前面一个任务完成,再执行后面一个任务,以此类推.这种模式的好处是实现起来比较简单 ...

  10. JavaScript异步机制

    单线程异步执行的JavaScript JavaScript是单线程异步执行的,单线程意味着代码在任务队列中会按照顺序一个接一个的执行.异步代表JavaScript代码在任务队列中的顺序并不完全等同于代 ...

随机推荐

  1. [ZZ] 用matlab绘制箭头

    用matlab绘制箭头 http://npfeng900.blog.163.com/blog/static/14456108201221922944998/ 用matlab绘制箭头1 用matlab绘 ...

  2. 存储专栏:一句话说清RAID2.0

     今天,西瓜哥来谈谈高端存储的一股势力,RAID 2.0,最近被华为HVS搞得风生水起,神奇的让人摸不着头脑.我还是从一个高端存储的江湖说起吧. 据说很久很久以前(别扔臭鸡蛋,讲故事都是这样的…),L ...

  3. 导出dmp

    如果有空表都需要导出执行 select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows= ...

  4. JVM-垃圾收集算法

    新生代:复制算法,IBM研究过,约98%对象是“朝生夕死”,所以不需要按照1:1来划分:HotSpot中默认是8:1:1,即每次新生代可用空间为90%,只有10%会被“浪费”, 当Survivor空间 ...

  5. python基础知识9---字符串拼接,深浅拷贝,三元运算

    一.字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3 ...

  6. 玩了下opencv的aruco(python版)

    简单的玩了下opencv里头的aruco,用的手机相机,手机装了个 ip摄像头,这样视频就可以传到电脑上了. 首先是标定,我没打印chessboard,直接在电脑屏幕上显示,拍了17张,大概如下: 又 ...

  7. awesome资源包

    .NET资源包 https://github.com/jobbole/awesome-dotnet-cn java资源包 https://github.com/jobbole/awesome-java ...

  8. 名称 ****不是有效的标识符 sql

    假设存储过程:proc_test create proc proc_test @ProdID varchar(10) as begin declare @sql varchar(max) @sql = ...

  9. 架构师技能图谱 V1.2

    系统架构能力 基本理论 扩展性设计 可用性设计 可靠性设计 一致性设计 负载均衡设计 过载保护设计 灾难恢复和备份 协议设计 二进制协议 文本协议 接入层架构设计 DNS 轮询 动静态分离 静态化 反 ...

  10. c语言函数参数类似继承的传递

    函数的参数如果是一个父结构的指针, 这个结构包含在另一个子结构中, typedef struct test_node_one test_node_one_t; typedef struct test_ ...