this.Invoke和this.BeginInvoke的区别
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Text = ""; this.Invoke(new EventHandler(delegate {
this.textBox1.Text += "";
})); this.textBox1.Text += "";
}
结果为:123
private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Text = ""; this.BeginInvoke(new EventHandler(delegate {
this.textBox1.Text += "";
})); this.textBox1.Text += "";
}
结果为: 132
结论:1、Invoke会阻止当前主线程的运行;BeginInvoke不会阻止当前主线程的运行,而是等当前主线程做完事情之后再执行BeginInvoke中的代码内容。
2、这2个方法都是由主线程运行的,并不是异步执行,如果代码耗时过长,同样会造成界面卡死
专业的介绍:http://blog.csdn.net/aptentity/article/details/5776762
this.Invoke和this.BeginInvoke的区别的更多相关文章
- [C#]this.Invoke和this.BeginInvoke的区别
private void button1_Click(object sender, EventArgs e) { "; this.Invoke(new EventHandler(delega ...
- 关于控件的Invoke(...)方法和BeginInvoke(...)方法的区别
这两个方法最主要的区别就是一个是同步,一个是异步,即会阻塞线程,那么阻塞哪个线程呢?我们用代码来分析(工具是VS2010) using System; using System.Collections ...
- (转)C#为什么要使用Invoke,它和BeginInvoke有什么区别
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...
- C#中Invoke 和 BeginInvoke 的区别
Control.Invoke 方法 (Delegate) :在拥有此控件的基础窗口句柄的线程上执行指定的委托. Control.BeginInvoke 方法 (Delegate) :在创建控件的基础句 ...
- Invoke 和 BeginInvoke 的区别
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是dot ...
- Invoke和BeginInvoke的区别(转载)
转自http://www.cnblogs.com/c2303191/articles/826571.html Control.Invoke 方法 (Delegate) :在拥有此控件的基础窗口句柄的线 ...
- Control.Invoke和Control.BeginInvoke
问题的引入 下面有个简单的demo,大家一看代码就知道效果如何示例.我新建一个winform的程序,然后写入了如下代码: using System; using System.Windows.Form ...
- 千万别在UI线程上调用Control.Invoke和Control.BeginInvoke,因为这些是依然阻塞UI线程的,造成界面的假死
原文地址:https://www.cnblogs.com/wangchuang/archive/2013/02/20/2918858.html .c# Invoke和BeginInvoke 区别 Co ...
- Invoke 和 BeginInvoke 的区别(转发)
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...
随机推荐
- Leetcode 9. Palindrome Number(判断回文数字)
Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...
- C# 4 dynamic 动态对象 动态类型转换
public class User { //使用省缺参数,一般不需要再为多态做各种静态重载了 public User( string name = "anonym", string ...
- Animated App Boot Example : Fastest animation at app boot time
This iPhone app shows how to create an animation that is displayed when the app starts. The animatio ...
- Javascript之简单按钮搜索功能
学习JavaScript我觉得真实的感觉就是可以任意设计,“没有做不到只有想不到!”即使简单,但是任何东西的复杂都是从简单.基础开始的!这是我自己做的一个超简单的"搜索引擎"按钮, ...
- Excel Operation
在日常工作中, 常常需要收集统计一些数据, 然后整理到excel, 这种重复性的操作可以自己写个工具来实现. 采用HtmlUnitDriver 访问页面, 抓取数据, 再把数据列表通过调用POI放到e ...
- 过程式编程 drawShapes
// // main.m // 3.2.1 过程式编程 #import <Foundation/Foundation.h> typedef enum { kCircle, kRectang ...
- web前端面试题收集(二)
简单介绍下你的前端代码开发与调试环境. Doctype声明的作用以及html4.01与html5中此声明的区别? 常用的块级元素与行内元素分别有哪些? 请画一下W3C盒模型 请写一个js函数,将url ...
- react服务端/客户端,同构代码心得
FKP-REST是一套全栈javascript框架 react服务端/客户端,同构代码心得 作者:webkixi react服务端/客户端,同构代码心得 服务端,客户端同构一套代码,大前端的梦想, ...
- @Autowired与@Resource用法
官方文档中有这样一段话. If you intend to express annotation-driven injection by name, do not primarily use @Aut ...
- centos7搭建NIS与NFS综合应用
实验环境: centos7(服务端) redhat enterprise linux 7.2(客户端) 实验目的:用centos7的账号,能在redhat enterprise linu ...