Code:
/ DotNET / DotNET / 8.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
- TableItemStyle.cs
- SqlError.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- RelatedCurrencyManager.cs
- QueryConverter.cs
- StringBlob.cs
- BufferModesCollection.cs
- DataControlImageButton.cs
- HttpDebugHandler.cs
- RewritingProcessor.cs
- ToolStripRenderer.cs
- BinaryUtilClasses.cs
- ListViewAutomationPeer.cs
- SourceSwitch.cs
- M3DUtil.cs
- LocalizableAttribute.cs
- ByteAnimation.cs
- KeyFrames.cs
- CompositeDataBoundControl.cs
- DataGridLinkButton.cs
- CodeGenHelper.cs
- XPathDescendantIterator.cs
- ToolTip.cs
- XmlNamespaceMapping.cs
- RectAnimationClockResource.cs
- TreePrinter.cs
- ColorContextHelper.cs
- SerializerProvider.cs
- MissingMethodException.cs
- StyleModeStack.cs
- RtType.cs
- Base64Decoder.cs
- Model3DCollection.cs
- LostFocusEventManager.cs
- CommandConverter.cs
- WebPageTraceListener.cs
- CodeMethodInvokeExpression.cs
- RSAPKCS1KeyExchangeFormatter.cs
- NamespaceList.cs
- TextMessageEncoder.cs
- MarkupCompilePass1.cs
- Registry.cs
- sortedlist.cs
- MultitargetUtil.cs
- IdnElement.cs
- ASCIIEncoding.cs
- IsolatedStorage.cs
- ChannelServices.cs
- ObservableDictionary.cs
- DataTrigger.cs
- XPathDocument.cs
- InlineUIContainer.cs
- ExtensionQuery.cs
- AssemblyName.cs
- ValidationErrorCollection.cs
- _LoggingObject.cs
- FlowDocumentView.cs
- RuntimeResourceSet.cs
- ResourcePermissionBaseEntry.cs
- WindowsProgressbar.cs
- CursorConverter.cs
- DocumentCollection.cs
- ADConnectionHelper.cs
- QilDataSource.cs
- SHA512Managed.cs
- Typography.cs
- DbSourceCommand.cs
- FocusManager.cs
- UrlAuthFailureHandler.cs
- SortDescriptionCollection.cs
- DataGridViewComboBoxColumn.cs
- WorkflowOwnershipException.cs
- GridSplitter.cs
- XmlSchema.cs
- PocoPropertyAccessorStrategy.cs
- ToolStripDropTargetManager.cs
- ExpandSegmentCollection.cs
- TemplatePartAttribute.cs
- SQLBytesStorage.cs
- MappingItemCollection.cs
- OdbcEnvironmentHandle.cs
- SQLInt64Storage.cs
- NaturalLanguageHyphenator.cs
- DoubleUtil.cs
- Encoder.cs
- DynamicMethod.cs
- RadioButtonList.cs
- ZipIOExtraField.cs
- HttpTransportBindingElement.cs
- OracleTransaction.cs
- ProviderConnectionPointCollection.cs
- DbConnectionPoolCounters.cs
- RemoteWebConfigurationHostServer.cs
- SmtpFailedRecipientException.cs
- EventHandlers.cs
- NegatedCellConstant.cs
- ObfuscateAssemblyAttribute.cs
- XmlSchemaExternal.cs
- DockProviderWrapper.cs
- HttpFormatExtensions.cs