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

  1. [C#]this.Invoke和this.BeginInvoke的区别

    private void button1_Click(object sender, EventArgs e) { "; this.Invoke(new EventHandler(delega ...

  2. 关于控件的Invoke(...)方法和BeginInvoke(...)方法的区别

    这两个方法最主要的区别就是一个是同步,一个是异步,即会阻塞线程,那么阻塞哪个线程呢?我们用代码来分析(工具是VS2010) using System; using System.Collections ...

  3. (转)C#为什么要使用Invoke,它和BeginInvoke有什么区别

    在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...

  4. C#中Invoke 和 BeginInvoke 的区别

    Control.Invoke 方法 (Delegate) :在拥有此控件的基础窗口句柄的线程上执行指定的委托. Control.BeginInvoke 方法 (Delegate) :在创建控件的基础句 ...

  5. Invoke 和 BeginInvoke 的区别

    在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是dot ...

  6. Invoke和BeginInvoke的区别(转载)

    转自http://www.cnblogs.com/c2303191/articles/826571.html Control.Invoke 方法 (Delegate) :在拥有此控件的基础窗口句柄的线 ...

  7. Control.Invoke和Control.BeginInvoke

    问题的引入 下面有个简单的demo,大家一看代码就知道效果如何示例.我新建一个winform的程序,然后写入了如下代码: using System; using System.Windows.Form ...

  8. 千万别在UI线程上调用Control.Invoke和Control.BeginInvoke,因为这些是依然阻塞UI线程的,造成界面的假死

    原文地址:https://www.cnblogs.com/wangchuang/archive/2013/02/20/2918858.html .c# Invoke和BeginInvoke 区别 Co ...

  9. Invoke 和 BeginInvoke 的区别(转发)

    在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate. 一.为什么Control类提供了Invoke和BeginInvoke机制? 关于这个问题的最主要的原因已经是do ...

随机推荐

  1. nmap命令-----基础用法

    系统漏洞扫描之王-nmap   NMap,也就是Network Mapper,是Linux下的网络扫描和嗅探工具包.   其基本功能有三个: (1)是扫描主机端口,嗅探所提供的网络服务 (2)是探测一 ...

  2. 在jQuery环境下制作轻巧遮罩层

    遮罩层的好处就是可以屏蔽用户对遮罩层下方元素的操作. 制作原理很简单:1设置遮罩层触发按钮 2设置遮罩层内容 3设置遮罩层背景(重点是捕获内容div的大小位置)4设置点击触发按钮遮罩层背景内容同时显示 ...

  3. Git CMD - status: Show the working tree status

    命令参数 git status [<options>…​] [--] [<pathspec>…​] 命令格式 --short, -s 短格式输出. -- long 长格式输出, ...

  4. Git CMD - rm: Remove files from the working tree and from the index

    命令格式 git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…​ 命令参 ...

  5. 删除SVN批处理(bat)

    添加批处理文件(deleteSVN.bat),文件内容: @echo off :start ::启动过程,切换目录 set pwd=%cd% cd %1 echo 工作目录是:& chdir ...

  6. Script 代码段

    script代码段 1.script代码段的执行 在Javascript代码中,可以使用script作为基本标识,script代码段在运行过程中是分段解析与执行的. 2.script代码段执行流程 在 ...

  7. 【leetcode】9. Palindrome Number

    题目描述: Determine whether an integer is a palindrome. Do this without extra space. 解题分析: ^_^个人觉得这道题没有什 ...

  8. 一个CFile::Remove引起的奇怪问题

    今天收到测试的一个反馈,我们的一个程序,在WIN7.WIN8下安装后,运行不起来,在进程列表中可以看到,但就是不出来窗口,同样的程序在XP下正常,在UAC关闭的情况下也正常,在以管理员权限运行时也正常 ...

  9. myeclipse 的 working set

    想必大家的myeclipse会有很多工程看的和不方便,那么怎么让它看的简洁一点呢,使用working set 会让你的目录看起来没有那么的多. 首先是怎么创建 working set  ,在新建时选择 ...

  10. Linux 获取文件夹下的所有文件

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4129616.html #include <string> #include &l ...