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
- InternalPolicyElement.cs
- glyphs.cs
- DeclarativeConditionsCollection.cs
- ValidationPropertyAttribute.cs
- XslCompiledTransform.cs
- SoapObjectWriter.cs
- DeferrableContent.cs
- BaseInfoTable.cs
- MissingFieldException.cs
- XmlNamedNodeMap.cs
- ImageList.cs
- HtmlTableCell.cs
- ListenerElementsCollection.cs
- ControlLocalizer.cs
- FacetValueContainer.cs
- Menu.cs
- IPEndPoint.cs
- EditorZone.cs
- TcpDuplicateContext.cs
- SignatureToken.cs
- WebPartEditorCancelVerb.cs
- FastEncoder.cs
- TreeView.cs
- TextBounds.cs
- Vector3DValueSerializer.cs
- EmissiveMaterial.cs
- OracleBinary.cs
- ScrollEvent.cs
- RoutedEventArgs.cs
- TextMessageEncodingElement.cs
- LockedActivityGlyph.cs
- ColorAnimationUsingKeyFrames.cs
- SortKey.cs
- DbDataSourceEnumerator.cs
- XmlSerializer.cs
- ActiveDocumentEvent.cs
- DataExpression.cs
- BinaryMessageEncoder.cs
- TryLoadRunnableWorkflowCommand.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- InplaceBitmapMetadataWriter.cs
- ScriptingWebServicesSectionGroup.cs
- CompilerGlobalScopeAttribute.cs
- TextDecorationCollection.cs
- HierarchicalDataBoundControl.cs
- SyndicationFeedFormatter.cs
- SoapIncludeAttribute.cs
- ImageCodecInfo.cs
- Activator.cs
- ScriptResourceMapping.cs
- ReferencedAssembly.cs
- FormsAuthenticationModule.cs
- MultiBindingExpression.cs
- BuildProviderAppliesToAttribute.cs
- ResourceManager.cs
- EntityDataSourceReferenceGroup.cs
- StyleXamlParser.cs
- QilStrConcatenator.cs
- ClientRolePrincipal.cs
- FrameworkTemplate.cs
- XsltException.cs
- StringExpressionSet.cs
- SqlConnectionPoolProviderInfo.cs
- XhtmlTextWriter.cs
- LambdaSerializationException.cs
- OdbcUtils.cs
- MouseEvent.cs
- SettingsPropertyNotFoundException.cs
- ImageDrawing.cs
- ToolStripGrip.cs
- Events.cs
- Evaluator.cs
- AddInPipelineAttributes.cs
- DataGridViewTextBoxColumn.cs
- ZipPackagePart.cs
- TextElementCollectionHelper.cs
- ExpressionBindingsDialog.cs
- TargetPerspective.cs
- DesigntimeLicenseContext.cs
- PathGeometry.cs
- MeasureData.cs
- CodeExporter.cs
- KeyboardNavigation.cs
- Matrix.cs
- Metadata.cs
- PaginationProgressEventArgs.cs
- DesignerForm.cs
- PreservationFileWriter.cs
- DecimalStorage.cs
- ClientRolePrincipal.cs
- Tuple.cs
- ResourceSetExpression.cs
- WebControl.cs
- BinaryMessageEncodingBindingElement.cs
- SendSecurityHeaderElementContainer.cs
- PointAnimationBase.cs
- AggregateException.cs
- NetworkInformationPermission.cs
- LayoutTable.cs
- SerializationBinder.cs