@@ -1208,17 +1208,17 @@ void IThreadPoolWorkItem.ExecuteWorkItem()
1208
1208
#if DEBUG
1209
1209
MarkExecuted ( false ) ;
1210
1210
#endif
1211
- if ( context != null )
1212
- {
1213
- ExecutionContext . Run ( context , ccb , this , true ) ;
1214
- }
1215
- else
1211
+ // call directly if it is an unsafe call OR EC flow is suppressed
1212
+ if ( context == null )
1216
1213
{
1217
- // call directly if it is an unsafe call OR EC flow is suppressed
1218
1214
WaitCallback cb = callback ;
1219
1215
callback = null ;
1220
1216
cb ( state ) ;
1221
1217
}
1218
+ else
1219
+ {
1220
+ ExecutionContext . Run ( context , ccb , this , true ) ;
1221
+ }
1222
1222
}
1223
1223
1224
1224
[ SecurityCritical ]
@@ -1679,19 +1679,10 @@ private static bool QueueUserWorkItemHelper(WaitCallback callBack, Object state,
1679
1679
ExecutionContext . Capture ( ref stackMark , ExecutionContext . CaptureOptions . IgnoreSyncCtx | ExecutionContext . CaptureOptions . OptimizeDefaultCase ) :
1680
1680
null ;
1681
1681
1682
- IThreadPoolWorkItem tpcallBack ;
1683
- if ( context == null )
1684
- {
1685
- tpcallBack = new QueueUserWorkItemCallback ( callBack , state , null ) ; // null context
1686
- }
1687
- else if ( context . IsDefaultFTContext ( true ) )
1688
- {
1689
- tpcallBack = new QueueUserWorkItemCallbackDefaultContext ( callBack , state ) ; // default context
1690
- }
1691
- else
1692
- {
1693
- tpcallBack = new QueueUserWorkItemCallback ( callBack , state , context ) ; // non-default context
1694
- }
1682
+ IThreadPoolWorkItem tpcallBack = context == ExecutionContext . PreAllocatedDefault ?
1683
+ new QueueUserWorkItemCallbackDefaultContext ( callBack , state ) :
1684
+ ( IThreadPoolWorkItem ) new QueueUserWorkItemCallback ( callBack , state , context ) ;
1685
+
1695
1686
ThreadPoolGlobals . workQueue . Enqueue ( tpcallBack , true ) ;
1696
1687
success = true ;
1697
1688
}
0 commit comments