Ash*_*shu 20 .net c# multithreading delegates
我有一个基于对话框的应用程序,我将I/O操作读写委托给不同的线程.
我只想清楚两种方法之间有什么区别..
第一种方法:(我这样做,我的主要形式-Form.cs)
delegate void Action();
Action _action = new Action(Method);
this.BeginInvoke(_action);
Run Code Online (Sandbox Code Playgroud)
第二种方法:
Thread th = new Thread( new ThreadStart(_action));
th.Start();
Run Code Online (Sandbox Code Playgroud)
我注意到BeginInvoke将UI挂起一秒钟,而第二种方法却没有.
请帮忙
BeginInvokes通过向窗口发布消息,在UI线程上异步执行委托(这就是它挂起UI的原因).如果委托中的代码访问UI,则需要执行此操作.
Thread.Start的方法在一个新的,独立的线程上执行委托.
| 归档时间: |
|
| 查看次数: |
26019 次 |
| 最近记录: |