Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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 // ////// 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); } // assert 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. //------------------------------------------------------------------------------ //[To be supplied.] ///// 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 // ////// 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); } // assert 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.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StyleTypedPropertyAttribute.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- DataTableCollection.cs
- TableAutomationPeer.cs
- CallInfo.cs
- HiddenFieldPageStatePersister.cs
- InvalidCommandTreeException.cs
- TokenBasedSetEnumerator.cs
- MetadataPropertyCollection.cs
- XPathSingletonIterator.cs
- InvalidWMPVersionException.cs
- WebPageTraceListener.cs
- RequestTimeoutManager.cs
- EventRoute.cs
- GroupBoxDesigner.cs
- XmlCountingReader.cs
- ZipIOCentralDirectoryFileHeader.cs
- SpecialTypeDataContract.cs
- LifetimeServices.cs
- CacheDependency.cs
- UserControlCodeDomTreeGenerator.cs
- DropSourceBehavior.cs
- SkipQueryOptionExpression.cs
- FixedTextSelectionProcessor.cs
- DelegateTypeInfo.cs
- CopyAttributesAction.cs
- StringToken.cs
- ObjectDataSourceFilteringEventArgs.cs
- CodeStatement.cs
- AspNetHostingPermission.cs
- DynamicDocumentPaginator.cs
- XmlMemberMapping.cs
- LookupNode.cs
- RestHandler.cs
- ProgressBarAutomationPeer.cs
- ControlPaint.cs
- ProcessThreadCollection.cs
- CommandEventArgs.cs
- MatrixTransform3D.cs
- AtlasWeb.Designer.cs
- CompositeActivityDesigner.cs
- FlowStep.cs
- ClientTargetCollection.cs
- XamlTreeBuilderBamlRecordWriter.cs
- RegistryKey.cs
- FillRuleValidation.cs
- TypeElement.cs
- SignalGate.cs
- HelpFileFileNameEditor.cs
- XmlSigningNodeWriter.cs
- CssStyleCollection.cs
- XmlAttributeAttribute.cs
- Wildcard.cs
- SecurityCriticalDataForSet.cs
- safex509handles.cs
- VBCodeProvider.cs
- ExtensionMethods.cs
- DeviceOverridableAttribute.cs
- ProxyGenerator.cs
- ObjectTypeMapping.cs
- CommandHelper.cs
- TextDecorations.cs
- ControlBuilder.cs
- Focus.cs
- GroupByQueryOperator.cs
- AppDomainGrammarProxy.cs
- XmlUtil.cs
- DecoratedNameAttribute.cs
- PageContentAsyncResult.cs
- AdRotator.cs
- ResizeGrip.cs
- SystemIPInterfaceStatistics.cs
- VisualState.cs
- DrawingContextDrawingContextWalker.cs
- ISSmlParser.cs
- TemplateControlParser.cs
- SqlUdtInfo.cs
- SqlFacetAttribute.cs
- WmlLabelAdapter.cs
- InvalidDocumentContentsException.cs
- HostProtectionException.cs
- PeerTransportListenAddressConverter.cs
- EditingCommands.cs
- MatrixAnimationBase.cs
- DataViewSetting.cs
- PrintDialog.cs
- XmlSerializerAssemblyAttribute.cs
- Mouse.cs
- LambdaCompiler.Lambda.cs
- SqlMethodAttribute.cs
- MemberInfoSerializationHolder.cs
- RadioButtonFlatAdapter.cs
- TabItemWrapperAutomationPeer.cs
- SortKey.cs
- MessageProperties.cs
- GcHandle.cs
- SpecialNameAttribute.cs
- UpdateCompiler.cs
- IsolatedStorageFileStream.cs
- BadImageFormatException.cs