Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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(); } } }[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- KeyManager.cs
- FastPropertyAccessor.cs
- CommonObjectSecurity.cs
- ReachSerializationCacheItems.cs
- AuthenticationSection.cs
- DecoderFallbackWithFailureFlag.cs
- HttpApplication.cs
- ColorPalette.cs
- ExitEventArgs.cs
- XmlQueryCardinality.cs
- SplitterCancelEvent.cs
- DirtyTextRange.cs
- MappingMetadataHelper.cs
- ConfigurationLocation.cs
- WebPartsPersonalizationAuthorization.cs
- PrivateFontCollection.cs
- EditingMode.cs
- WorkflowInstanceExtensionProvider.cs
- NoneExcludedImageIndexConverter.cs
- ContentControl.cs
- PingReply.cs
- Pair.cs
- ConfigurationStrings.cs
- MinimizableAttributeTypeConverter.cs
- FileFormatException.cs
- ExpressionPrefixAttribute.cs
- ViewGenerator.cs
- SelectManyQueryOperator.cs
- XmlBindingWorker.cs
- WorkflowDesignerColors.cs
- CachedPathData.cs
- Matrix.cs
- StrokeSerializer.cs
- TableMethodGenerator.cs
- _HeaderInfo.cs
- SelectionItemProviderWrapper.cs
- ExtensionFile.cs
- RemotingException.cs
- RuntimeHandles.cs
- DataObjectEventArgs.cs
- WinFormsSecurity.cs
- EntityDesignerDataSourceView.cs
- AppDomainManager.cs
- _OverlappedAsyncResult.cs
- RootProfilePropertySettingsCollection.cs
- EntityTypeEmitter.cs
- ToolStripDropDownButton.cs
- ForeignKeyConstraint.cs
- X509CertificateChain.cs
- ProgressBarBrushConverter.cs
- BindingMAnagerBase.cs
- URLString.cs
- AnnotationAuthorChangedEventArgs.cs
- SystemUnicastIPAddressInformation.cs
- Console.cs
- Message.cs
- SqlUnionizer.cs
- RuntimeIdentifierPropertyAttribute.cs
- ExpandButtonVisibilityConverter.cs
- XmlSequenceWriter.cs
- Switch.cs
- RequestQueryParser.cs
- ConnectionPointConverter.cs
- RuntimeConfigurationRecord.cs
- BoundField.cs
- TimeSpanValidator.cs
- MexHttpsBindingElement.cs
- Bidi.cs
- AttachmentCollection.cs
- _emptywebproxy.cs
- AutomationEventArgs.cs
- Util.cs
- HttpCookiesSection.cs
- PageSettings.cs
- UndoManager.cs
- Point3DAnimationBase.cs
- PreloadedPackages.cs
- HealthMonitoringSection.cs
- ProcessThread.cs
- EmptyEnumerable.cs
- ContractMapping.cs
- ResourceExpressionBuilder.cs
- CompilerScope.Storage.cs
- TreeBuilderBamlTranslator.cs
- WebPart.cs
- DashStyles.cs
- XmlIncludeAttribute.cs
- WebScriptEnablingElement.cs
- PathStreamGeometryContext.cs
- TimeSpan.cs
- ListBindableAttribute.cs
- IRCollection.cs
- DoubleKeyFrameCollection.cs
- OutOfProcStateClientManager.cs
- SymmetricKeyWrap.cs
- UIPermission.cs
- _ListenerRequestStream.cs
- HuffModule.cs
- ComponentEditorForm.cs
- SafeEventLogWriteHandle.cs