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
//
///
/// [To be supplied.]
///
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();
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AsyncPostBackTrigger.cs
- SafePEFileHandle.cs
- ConfigurationElement.cs
- MetaTable.cs
- PropertyValidationContext.cs
- IsolatedStoragePermission.cs
- ObjectSet.cs
- diagnosticsswitches.cs
- Validator.cs
- BindingValueChangedEventArgs.cs
- VoiceChangeEventArgs.cs
- NamedElement.cs
- BindingsCollection.cs
- PeerNearMe.cs
- IFlowDocumentViewer.cs
- VirtualizingStackPanel.cs
- ButtonRenderer.cs
- TabItemAutomationPeer.cs
- FileLoadException.cs
- FontUnit.cs
- CollectionViewGroupInternal.cs
- FunctionImportMapping.cs
- EtwTrace.cs
- CellTreeNode.cs
- IdentityModelStringsVersion1.cs
- Tablet.cs
- Module.cs
- AutomationPatternInfo.cs
- DataGridTableCollection.cs
- DataGridCell.cs
- WizardForm.cs
- ClientConfigurationHost.cs
- Padding.cs
- FilterEventArgs.cs
- ZipFileInfoCollection.cs
- BamlTreeNode.cs
- DataListItemEventArgs.cs
- NullReferenceException.cs
- StatusBarAutomationPeer.cs
- assertwrapper.cs
- EntryIndex.cs
- PropertyGridCommands.cs
- BitmapEffectState.cs
- MenuCommand.cs
- DataTemplate.cs
- NavigationProgressEventArgs.cs
- DataAdapter.cs
- SiteMapNodeItemEventArgs.cs
- ChannelCacheDefaults.cs
- GridViewColumnCollection.cs
- MappingModelBuildProvider.cs
- UICuesEvent.cs
- CodeArrayCreateExpression.cs
- SmiXetterAccessMap.cs
- PropertyChangedEventArgs.cs
- safelink.cs
- SafeThreadHandle.cs
- AsyncOperationManager.cs
- ColorConvertedBitmapExtension.cs
- ListViewDeleteEventArgs.cs
- ValidationSummary.cs
- BitmapEffectGeneralTransform.cs
- HttpProcessUtility.cs
- DiscreteKeyFrames.cs
- EncryptedKeyHashIdentifierClause.cs
- RubberbandSelector.cs
- ActiveXSite.cs
- FileStream.cs
- ConsumerConnectionPoint.cs
- ToolStripDesignerAvailabilityAttribute.cs
- DesignerView.Commands.cs
- XmlNodeComparer.cs
- BitFlagsGenerator.cs
- HtmlInputImage.cs
- VirtualizedItemProviderWrapper.cs
- DataGridHeadersVisibilityToVisibilityConverter.cs
- TabPage.cs
- ToolStripPanelDesigner.cs
- RbTree.cs
- securitymgrsite.cs
- HttpApplicationFactory.cs
- FileDataSourceCache.cs
- MatrixKeyFrameCollection.cs
- DbgCompiler.cs
- xmlsaver.cs
- SourceItem.cs
- MetadataPropertyCollection.cs
- BroadcastEventHelper.cs
- MimeParameters.cs
- ExpandoClass.cs
- QueryHandler.cs
- CapiSymmetricAlgorithm.cs
- SortAction.cs
- DeflateStream.cs
- ByteStorage.cs
- ProcessInfo.cs
- DbConnectionHelper.cs
- ReadContentAsBinaryHelper.cs
- InvokeWebServiceDesigner.cs
- StringUtil.cs