Do both BeginInvoke and EndInvoke on delegates generate full fences?
Threading in C# by Joseph Albahari talks briefly about it, stating:
The following implicitly generate full fences:
- C#'s lock statement (Monitor.Enter/Monitor.Exit)
- All methods on the Interlocked class (we’ll cover these soon)
- Asynchronous callbacks that use the thread pool — these include asynchronous delegates, APM callbacks, and Task continuations
- Setting and waiting on a signaling construct
- Anything that relies on signaling, such as starting or waiting on a Task
As "asynchronous delegates" is in the list, I'd assume that at least EndInvoke is fully fenced. But what about BeginInvoke? Unfortunately I couldn't F11 (= debug step) into the BeginInvoke code - is the source available somewhere? Although a link t开发者_开发百科o a definite answer would be even better.
MSDN says BeginInvoke is threadsafe: http://msdn.microsoft.com/en-us/library/0b1bf3y3.aspx
there are four methods on a control that are thread safe: Invoke, BeginInvoke, EndInvoke, and CreateGraphics if the handle for the control has already been created
The source code the entire framework is available from Microsoft at the Reference Source Website
精彩评论