Does Func<T>.BeginInvoke use the ThreadPool? Does Func<T>.BeginInvoke use the ThreadPool? multithreading multithreading

Does Func<T>.BeginInvoke use the ThreadPool?


It uses the thread pool, definitely.

I'm blowed if I can find that documented anyway, mind you... this MSDN article indicates that any callback you specify will be executed on a thread-pool thread...

Here's some code to confirm it - but of course that doesn't confirm that it's guaranteed to happen that way...

using System;using System.Threading;public class Test{    static void Main()    {        Action x = () =>             Console.WriteLine(Thread.CurrentThread.IsThreadPoolThread);        x(); // Synchronous; prints False        x.BeginInvoke(null, null); // On the thread-pool thread; prints True        Thread.Sleep(500); // Let the previous call finish    }}

EDIT: As linked by Jeff below, this MSDN article confirms it:

If the BeginInvoke method is called, the common language runtime (CLR) queues the request and returns immediately to the caller. The target method is called asynchronously on a thread from the thread pool.


"Executes the specified delegate asynchronously on the thread that the control's underlying handle was created on." - MSDN

The above is for Controls, but probably can be assumed to be the same functionality for Func's as well. BeginInvoke allows you to execute of your Func from another Thread, but won't create threads for you. So Jon Skeet would be correct. Unless you are creating threads for asynchronous execution I wouldn't even use this feature cause it won't buy you anything over just calling Invoke.