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
- CompoundFileReference.cs
- TriggerAction.cs
- ToggleProviderWrapper.cs
- EventProviderWriter.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- LayoutEditorPart.cs
- MSAANativeProvider.cs
- XamlInt32CollectionSerializer.cs
- CompilerInfo.cs
- XmlUtf8RawTextWriter.cs
- Stylus.cs
- RadioButtonStandardAdapter.cs
- WebPart.cs
- Exceptions.cs
- ClientSession.cs
- ColorConvertedBitmapExtension.cs
- CorrelationScope.cs
- UnsafeNativeMethods.cs
- ExpressionVisitor.cs
- EventsTab.cs
- ProviderCollection.cs
- ListViewUpdatedEventArgs.cs
- DesignSurfaceManager.cs
- RegexCode.cs
- SqlNotificationRequest.cs
- DataGridViewComboBoxColumnDesigner.cs
- OptimisticConcurrencyException.cs
- AppSettingsExpressionBuilder.cs
- UnknownBitmapDecoder.cs
- Message.cs
- ObfuscateAssemblyAttribute.cs
- ExtractorMetadata.cs
- Button.cs
- Schema.cs
- ClientRoleProvider.cs
- AnonymousIdentificationModule.cs
- ShaperBuffers.cs
- FontFamilyConverter.cs
- SortQuery.cs
- PagedDataSource.cs
- WindowInteractionStateTracker.cs
- ParserStreamGeometryContext.cs
- KernelTypeValidation.cs
- MsmqIntegrationSecurityElement.cs
- TypeInfo.cs
- SafeRightsManagementQueryHandle.cs
- CoTaskMemHandle.cs
- NullExtension.cs
- BindingsCollection.cs
- Bold.cs
- IsolatedStorageFileStream.cs
- AmbientLight.cs
- MatrixTransform.cs
- BaseProcessor.cs
- BinaryObjectInfo.cs
- VerticalAlignConverter.cs
- SQLInt32Storage.cs
- GridViewPageEventArgs.cs
- TextParagraph.cs
- DataServiceKeyAttribute.cs
- SpotLight.cs
- ErrorReporting.cs
- DLinqDataModelProvider.cs
- KeyTime.cs
- TokenDescriptor.cs
- QuaternionConverter.cs
- JsonGlobals.cs
- TextEditorDragDrop.cs
- securestring.cs
- SingleKeyFrameCollection.cs
- DynamicRenderer.cs
- TextTreeTextNode.cs
- GradientStopCollection.cs
- Quaternion.cs
- versioninfo.cs
- FrugalList.cs
- FrameSecurityDescriptor.cs
- SerializationAttributes.cs
- SchemaNamespaceManager.cs
- TextContainerChangedEventArgs.cs
- DesignerActionUIService.cs
- OperationAbortedException.cs
- MonikerHelper.cs
- DetailsView.cs
- DataListItem.cs
- ObjectDisposedException.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- SiteMapPath.cs
- XpsFixedPageReaderWriter.cs
- TemplateFactory.cs
- ConnectorMovedEventArgs.cs
- SettingsPropertyValue.cs
- PerfCounters.cs
- TriState.cs
- GlyphRunDrawing.cs
- RemotingConfigParser.cs
- ReflectEventDescriptor.cs
- PolyLineSegment.cs
- ManagementExtension.cs
- IisTraceWebEventProvider.cs