Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / WorkItem.cs / 1305376 / 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.] ////// 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.] ////// 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
- BufferedMessageData.cs
- TimeSpanValidator.cs
- WebBrowserNavigatingEventHandler.cs
- AlphabeticalEnumConverter.cs
- BuildProviderInstallComponent.cs
- DefaultBindingPropertyAttribute.cs
- ErrorFormatter.cs
- XmlILConstructAnalyzer.cs
- StrokeCollection2.cs
- WebServiceMethodData.cs
- MethodCallTranslator.cs
- DataControlField.cs
- DataGridViewTextBoxColumn.cs
- PageParser.cs
- ToolStripComboBox.cs
- XmlException.cs
- HttpWebRequestElement.cs
- PrincipalPermission.cs
- AbsoluteQuery.cs
- DataBindingExpressionBuilder.cs
- WebPartZoneDesigner.cs
- Int16AnimationUsingKeyFrames.cs
- StringKeyFrameCollection.cs
- CapabilitiesRule.cs
- DrawItemEvent.cs
- SafeCryptoHandles.cs
- Latin1Encoding.cs
- OutputCacheModule.cs
- InboundActivityHelper.cs
- Model3DGroup.cs
- PackageFilter.cs
- CommonObjectSecurity.cs
- ReferenceConverter.cs
- URIFormatException.cs
- RSAOAEPKeyExchangeFormatter.cs
- ConfigurationValidatorAttribute.cs
- RawMouseInputReport.cs
- DateTimeFormat.cs
- GlyphRun.cs
- XmlSchemaSimpleContentExtension.cs
- VisualStates.cs
- ConnectionsZone.cs
- ExtendedProtectionPolicy.cs
- InteropBitmapSource.cs
- IDReferencePropertyAttribute.cs
- HyperLinkColumn.cs
- ReaderOutput.cs
- ContourSegment.cs
- SpellerStatusTable.cs
- EdmComplexTypeAttribute.cs
- RunClient.cs
- CharacterMetricsDictionary.cs
- LoginCancelEventArgs.cs
- StrokeNode.cs
- XmlDataSource.cs
- BitmapEffectGroup.cs
- ResolvedKeyFrameEntry.cs
- DiscardableAttribute.cs
- CodeMethodInvokeExpression.cs
- PictureBoxDesigner.cs
- HighlightVisual.cs
- KeyTime.cs
- Tag.cs
- EventProviderBase.cs
- AutomationElementCollection.cs
- ExpressionHelper.cs
- SimpleFileLog.cs
- PropertyTabChangedEvent.cs
- SqlGenericUtil.cs
- _SafeNetHandles.cs
- JavascriptCallbackBehaviorAttribute.cs
- PaperSource.cs
- XamlFxTrace.cs
- QueryContinueDragEvent.cs
- TimeSpanMinutesConverter.cs
- LambdaCompiler.cs
- CompiledQuery.cs
- Sql8ExpressionRewriter.cs
- ConsumerConnectionPoint.cs
- ForeignKeyConstraint.cs
- ObjectReaderCompiler.cs
- SelectionGlyph.cs
- ConnectionConsumerAttribute.cs
- TypeListConverter.cs
- LayoutTable.cs
- SqlCacheDependencyDatabase.cs
- TypeNameParser.cs
- DefaultWorkflowLoaderService.cs
- BackEase.cs
- mediaeventargs.cs
- DoubleAnimationUsingPath.cs
- XslAst.cs
- FileSystemInfo.cs
- ListDictionaryInternal.cs
- hresults.cs
- BitmapEffectGeneralTransform.cs
- PerfCounterSection.cs
- BindingCollection.cs
- CompressionTransform.cs
- ImpersonationContext.cs