Code:
/ 4.0 / 4.0 / untmp / 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.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlConnectionFactory.cs
- DocumentOrderComparer.cs
- figurelength.cs
- SystemColorTracker.cs
- ValueUtilsSmi.cs
- TableCellCollection.cs
- ScriptHandlerFactory.cs
- InternalDispatchObject.cs
- CustomLineCap.cs
- ProfileEventArgs.cs
- Control.cs
- Comparer.cs
- AllowedAudienceUriElementCollection.cs
- EntityTemplateUserControl.cs
- SqlMetaData.cs
- MachineKey.cs
- XmlSerializationWriter.cs
- DataGridViewCheckBoxColumn.cs
- ConfigurationFileMap.cs
- ReadOnlyHierarchicalDataSourceView.cs
- UrlPropertyAttribute.cs
- SessionEndedEventArgs.cs
- DataGridViewControlCollection.cs
- SubclassTypeValidatorAttribute.cs
- TextLine.cs
- TemplateKeyConverter.cs
- ToolStripRendererSwitcher.cs
- TrackingProfileCache.cs
- WindowsTooltip.cs
- FactoryRecord.cs
- VSWCFServiceContractGenerator.cs
- ListComponentEditor.cs
- NetTcpSection.cs
- DataGridTextBoxColumn.cs
- InteropBitmapSource.cs
- InputReferenceExpression.cs
- ManipulationDevice.cs
- RelatedView.cs
- Assert.cs
- Rfc2898DeriveBytes.cs
- EntityConnectionStringBuilderItem.cs
- ListParaClient.cs
- RSAProtectedConfigurationProvider.cs
- DependencyPropertyConverter.cs
- CoreSwitches.cs
- AttributeData.cs
- NoClickablePointException.cs
- ZoomPercentageConverter.cs
- CommentAction.cs
- BinaryCommonClasses.cs
- ToolStripRenderer.cs
- TableCellAutomationPeer.cs
- NamespaceList.cs
- BinHexDecoder.cs
- WebSysDisplayNameAttribute.cs
- Script.cs
- SharedStatics.cs
- InputLangChangeRequestEvent.cs
- RoleService.cs
- CompiledQuery.cs
- ServiceDescription.cs
- XDRSchema.cs
- CngProperty.cs
- Stack.cs
- GlyphManager.cs
- WebZone.cs
- sqlstateclientmanager.cs
- ClassData.cs
- LoginNameDesigner.cs
- MemberDescriptor.cs
- precedingquery.cs
- SessionState.cs
- DictionaryEditChange.cs
- TimeSpanValidatorAttribute.cs
- TranslateTransform.cs
- DockProviderWrapper.cs
- PasswordBoxAutomationPeer.cs
- XmlDesigner.cs
- DateTimeConverter2.cs
- ObjectConverter.cs
- BoundField.cs
- GridEntry.cs
- DoubleUtil.cs
- PrintingPermissionAttribute.cs
- TemplatePropertyEntry.cs
- ThreadNeutralSemaphore.cs
- RegexNode.cs
- ProjectionPlan.cs
- SizeIndependentAnimationStorage.cs
- xmlformatgeneratorstatics.cs
- SettingsPropertyNotFoundException.cs
- AppDomainGrammarProxy.cs
- ResourceDisplayNameAttribute.cs
- DataGridViewUtilities.cs
- ConditionCollection.cs
- XamlInt32CollectionSerializer.cs
- ResourceAssociationTypeEnd.cs
- ToolboxCategoryItems.cs
- DataControlExtensions.cs
- FilterableAttribute.cs