Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / 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); } // assertt 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. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ //[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.] ////// [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); } // assertt 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. // Copyright (c) Microsoft Corporation. All rights reserved.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HandleCollector.cs
- OleDbFactory.cs
- NamespaceInfo.cs
- Logging.cs
- ObjectDataSourceMethodEventArgs.cs
- UnsafeNativeMethods.cs
- ColorMatrix.cs
- DirectoryRedirect.cs
- TextFormatterImp.cs
- TableLayout.cs
- DesignConnection.cs
- ContextBase.cs
- HandlerBase.cs
- GridViewColumnCollection.cs
- StylusSystemGestureEventArgs.cs
- ConfigXmlWhitespace.cs
- SqlFunctionAttribute.cs
- CompilerGeneratedAttribute.cs
- BrowserCapabilitiesFactoryBase.cs
- OleDbMetaDataFactory.cs
- ZoneMembershipCondition.cs
- CacheAxisQuery.cs
- ConfigurationManagerHelperFactory.cs
- MessagePropertyVariants.cs
- UrlAuthFailedErrorFormatter.cs
- ObjectStorage.cs
- SqlServer2KCompatibilityCheck.cs
- PenCursorManager.cs
- SchemeSettingElement.cs
- StaticDataManager.cs
- PinnedBufferMemoryStream.cs
- SamlAuthorityBinding.cs
- ScrollViewer.cs
- PageAsyncTask.cs
- ToolStripControlHost.cs
- _NegotiateClient.cs
- MULTI_QI.cs
- panel.cs
- StrongTypingException.cs
- SqlUserDefinedAggregateAttribute.cs
- SqlProcedureAttribute.cs
- SoapIgnoreAttribute.cs
- EqualityComparer.cs
- PopupControlService.cs
- EDesignUtil.cs
- Converter.cs
- XslCompiledTransform.cs
- PingReply.cs
- FocusChangedEventArgs.cs
- TreeSet.cs
- SharedPerformanceCounter.cs
- FixedHyperLink.cs
- PositiveTimeSpanValidatorAttribute.cs
- BindingMAnagerBase.cs
- HtmlForm.cs
- DynamicILGenerator.cs
- CodeMethodReturnStatement.cs
- ListenerSingletonConnectionReader.cs
- Automation.cs
- VirtualizedItemPattern.cs
- MonitoringDescriptionAttribute.cs
- CssClassPropertyAttribute.cs
- MdImport.cs
- AccessViolationException.cs
- TableCellAutomationPeer.cs
- WindowsFormsHost.cs
- ToolStripContentPanel.cs
- NamespaceTable.cs
- ButtonFieldBase.cs
- GridItemPatternIdentifiers.cs
- XmlSerializerVersionAttribute.cs
- TypeConverterHelper.cs
- TreeViewImageIndexConverter.cs
- SendingRequestEventArgs.cs
- StoryFragments.cs
- DataTableCollection.cs
- ViewValidator.cs
- OleDbParameter.cs
- XomlCompiler.cs
- FormsAuthentication.cs
- MethodCallTranslator.cs
- DataView.cs
- MatrixConverter.cs
- DataTableReader.cs
- ToolStripButton.cs
- MsmqIntegrationProcessProtocolHandler.cs
- XsdBuildProvider.cs
- RegexCompilationInfo.cs
- Permission.cs
- RelationshipManager.cs
- TypeRestriction.cs
- DataColumnCollection.cs
- HttpProfileBase.cs
- CodeGenerator.cs
- fixedPageContentExtractor.cs
- ProtocolsConfiguration.cs
- ExpressionList.cs
- FixedTextView.cs
- DocumentAutomationPeer.cs
- BuildManager.cs