Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / fx / src / xsp / System / Web / Util / WorkItem.cs / 1 / WorkItem.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Util {
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Threading;
//
// Support for positing of work items to a different thread
//
///
/// [To be supplied.]
///
public delegate void WorkItemCallback();
///
/// [To be supplied.]
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class WorkItem {
private static bool _useQueueUserWorkItem = true;
private static WaitCallback _onQueueUserWorkItemCompletion = new WaitCallback(OnQueueUserWorkItemCompletion);
///
/// [To be supplied.]
///
[SecurityPermission(SecurityAction.Demand, Unrestricted=true)]
public static void Post(WorkItemCallback callback) {
#if !FEATURE_PAL // ROTORTODO
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
throw new PlatformNotSupportedException(SR.GetString(SR.RequiresNT));
#else // !FEATURE_PAL
throw new NotImplementedException("ROTORTODO");
#endif // !FEATURE_PAL
PostInternal(callback);
}
// assertt to disregard the user code up the compressed stack
[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
private static void CallCallbackWithAssert(WorkItemCallback callback) {
callback();
}
private static void OnQueueUserWorkItemCompletion(Object state) {
WorkItemCallback callback = state as WorkItemCallback;
if (callback != null) {
CallCallbackWithAssert(callback);
}
}
internal static void PostInternal(WorkItemCallback callback) {
if (_useQueueUserWorkItem) {
ThreadPool.QueueUserWorkItem(_onQueueUserWorkItemCompletion, callback);
}
else {
WrappedWorkItemCallback w = new WrappedWorkItemCallback(callback);
w.Post();
}
}
}
internal class WrappedWorkItemCallback {
private GCHandle _rootedThis;
private WorkItemCallback _originalCallback;
private WorkItemCallback _wrapperCallback;
internal WrappedWorkItemCallback(WorkItemCallback callback) {
_originalCallback = callback;
_wrapperCallback = new WorkItemCallback(this.OnCallback);
}
internal void Post() {
_rootedThis = GCHandle.Alloc(this);
if (UnsafeNativeMethods.PostThreadPoolWorkItem(_wrapperCallback) != 1) {
_rootedThis.Free();
throw new HttpException(SR.GetString(SR.Cannot_post_workitem));
}
}
private void OnCallback() {
_rootedThis.Free();
_originalCallback();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WindowsToolbarAsMenu.cs
- XmlSchemaImport.cs
- MasterPageCodeDomTreeGenerator.cs
- CodeDesigner.cs
- CommentEmitter.cs
- TreeBuilder.cs
- TextProviderWrapper.cs
- MergeFailedEvent.cs
- DeleteHelper.cs
- LabelAutomationPeer.cs
- DropShadowBitmapEffect.cs
- GuidelineCollection.cs
- WebEvents.cs
- DynamicPropertyReader.cs
- SemanticBasicElement.cs
- OdbcCommandBuilder.cs
- COM2ComponentEditor.cs
- SoapFaultCodes.cs
- InstanceValue.cs
- DataBoundControl.cs
- Configuration.cs
- HelpEvent.cs
- RuleInfoComparer.cs
- NativeCompoundFileAPIs.cs
- DataChangedEventManager.cs
- WorkflowRuntime.cs
- RenderData.cs
- RotateTransform3D.cs
- TransactionProtocolConverter.cs
- StoreItemCollection.Loader.cs
- StorageEntityContainerMapping.cs
- InkCollectionBehavior.cs
- TdsParserStateObject.cs
- DropShadowBitmapEffect.cs
- PersonalizationProvider.cs
- DictionaryManager.cs
- XmlMembersMapping.cs
- DateTimeOffsetStorage.cs
- CapacityStreamGeometryContext.cs
- MasterPageBuildProvider.cs
- JobCollate.cs
- JapaneseCalendar.cs
- BooleanExpr.cs
- List.cs
- RadioButton.cs
- ImageSourceValueSerializer.cs
- Error.cs
- MemberMaps.cs
- RequestBringIntoViewEventArgs.cs
- MatrixKeyFrameCollection.cs
- HelpPage.cs
- ManagedWndProcTracker.cs
- ClientRoleProvider.cs
- safemediahandle.cs
- GeometryValueSerializer.cs
- TypeTypeConverter.cs
- ModulesEntry.cs
- X500Name.cs
- xamlnodes.cs
- userdatakeys.cs
- WindowsListViewGroup.cs
- Container.cs
- EnumBuilder.cs
- DataGridItem.cs
- Rect3D.cs
- InvalidOleVariantTypeException.cs
- DelegateSerializationHolder.cs
- IdentityManager.cs
- FlowDocumentScrollViewer.cs
- ListBoxItem.cs
- ListView.cs
- PartialTrustHelpers.cs
- StateChangeEvent.cs
- System.Data.OracleClient_BID.cs
- ScriptReference.cs
- SecurityKeyUsage.cs
- DataSourceControlBuilder.cs
- GenericsInstances.cs
- SmtpCommands.cs
- GraphicsContainer.cs
- SoapSchemaImporter.cs
- InputScope.cs
- BitmapEffectInputConnector.cs
- returneventsaver.cs
- KeyboardNavigation.cs
- AttachedPropertyBrowsableAttribute.cs
- CallbackHandler.cs
- SqlCacheDependency.cs
- WebHttpSecurityElement.cs
- BasicExpandProvider.cs
- FillBehavior.cs
- DataGridViewButtonCell.cs
- SqlInfoMessageEvent.cs
- MenuItemAutomationPeer.cs
- DataGridViewSelectedColumnCollection.cs
- DSACryptoServiceProvider.cs
- WebPartCollection.cs
- PropertyChangedEventArgs.cs
- DataError.cs
- TiffBitmapDecoder.cs