Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- Brush.cs
- WindowsFormsLinkLabel.cs
- RawStylusInput.cs
- ValueExpressions.cs
- Automation.cs
- WebPartEditorCancelVerb.cs
- OpenTypeLayoutCache.cs
- BreakRecordTable.cs
- ByteRangeDownloader.cs
- DocumentPageView.cs
- ResolveNextArgumentWorkItem.cs
- WebPartDescription.cs
- RemoveFromCollection.cs
- SourceFilter.cs
- FontInfo.cs
- Random.cs
- ValueConversionAttribute.cs
- DecimalAnimation.cs
- ColorConverter.cs
- TransactionsSectionGroup.cs
- MenuItemStyle.cs
- FtpWebResponse.cs
- BaseValidatorDesigner.cs
- OleDbException.cs
- MimePart.cs
- EventLevel.cs
- DataMember.cs
- IWorkflowDebuggerService.cs
- LoadGrammarCompletedEventArgs.cs
- BorderGapMaskConverter.cs
- MemberPath.cs
- ConstructorExpr.cs
- WebZone.cs
- ModelItemDictionaryImpl.cs
- DefaultSerializationProviderAttribute.cs
- DocumentScope.cs
- PeerNodeTraceRecord.cs
- typedescriptorpermissionattribute.cs
- RoleGroup.cs
- TypeContext.cs
- CellTreeNodeVisitors.cs
- RangeBase.cs
- BasicHttpMessageCredentialType.cs
- SqlConnectionPoolGroupProviderInfo.cs
- HttpCapabilitiesEvaluator.cs
- DiagnosticTraceSchemas.cs
- DateTimeParse.cs
- StoreItemCollection.cs
- ChannelFactoryBase.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- ListViewItemEventArgs.cs
- HtmlFormWrapper.cs
- NotifyParentPropertyAttribute.cs
- UInt32.cs
- ServicePointManager.cs
- SelectionEditor.cs
- XslUrlEditor.cs
- DbProviderFactories.cs
- WebResourceAttribute.cs
- TransactionManager.cs
- ADMembershipProvider.cs
- AsnEncodedData.cs
- ContentElement.cs
- MaskedTextBox.cs
- Helper.cs
- SoapMessage.cs
- _FixedSizeReader.cs
- HTMLTextWriter.cs
- BitConverter.cs
- updateconfighost.cs
- ViewManagerAttribute.cs
- CodePrimitiveExpression.cs
- LocationUpdates.cs
- ExpressionNode.cs
- TableParaClient.cs
- HandledEventArgs.cs
- EventMemberCodeDomSerializer.cs
- WebPartVerbCollection.cs
- XmlSchemaExternal.cs
- securitycriticaldataClass.cs
- ICollection.cs
- AssemblyFilter.cs
- SignatureResourcePool.cs
- ResourcesChangeInfo.cs
- SamlConditions.cs
- AssertFilter.cs
- CollectionBase.cs
- InvalidComObjectException.cs
- TypeSystemProvider.cs
- MultiPartWriter.cs
- EarlyBoundInfo.cs
- ContextProperty.cs
- XmlILStorageConverter.cs
- HtmlInputCheckBox.cs
- MouseButtonEventArgs.cs
- FileUpload.cs
- SingleObjectCollection.cs
- WorkflowApplicationAbortedException.cs
- ObjectToIdCache.cs
- OleDbConnection.cs