开发者

Difference between Delegate.BeginInvoke and Thread.Start

开发者 https://www.devze.com 2022-12-29 11:38 出处:网络
Existing related questions here talk about differences between: 开发者_运维百科Delegate.BeginInvoke and Control.BeginInvoke

Existing related questions here talk about differences between:

But what are the differences between Delegate.BeginInvoke and Thread.Start?


Thread.Start starts a new OS thread to execute the delegate. When the delegate returns, the thread is destroyed. This is quite a heavy-weight operation (starting and destroying a thread) so you typically only do it if the method is going to be long-running.

Delegate.BeginInvoke will call the delegate on a thread pool thread. Once the method returns, the thread is returned to the pool to be reused by another task. The advantage of this is that queueing a method to the thread pool is relatively light-weight because you don't have to spin up a whole new thread every time.

Control.BeginInvoke invokes the method on the thread for the control. UI components are inherently single-threaded and every interaction with a UI control must be done on the thread that created it. Control.BeginInvoke is a handy way to do that.


  • Delegate.BeginInvoke uses the ThreadPool to execute the method (See MSDN).

  • Thread.Start creates a full new thread.

See this question: differences in the different ways to make concurrent programs for more info on the differences between the various ways of running concurrent code in .net.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号