Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// 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();
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- sitestring.cs
- AppDomainCompilerProxy.cs
- FlowDocumentPaginator.cs
- UiaCoreApi.cs
- XsdCachingReader.cs
- SafeLibraryHandle.cs
- XmlElement.cs
- DataSetMappper.cs
- KeyConverter.cs
- InlineCollection.cs
- RootBrowserWindowAutomationPeer.cs
- UndoManager.cs
- XhtmlBasicTextBoxAdapter.cs
- UndirectedGraph.cs
- EventLogger.cs
- PopupRootAutomationPeer.cs
- SqlNotificationRequest.cs
- RectAnimation.cs
- FormParameter.cs
- OracleException.cs
- RemoteWebConfigurationHostStream.cs
- BooleanAnimationBase.cs
- BitmapEffect.cs
- VisemeEventArgs.cs
- HasCopySemanticsAttribute.cs
- DbReferenceCollection.cs
- PanelStyle.cs
- ApplicationId.cs
- WmlTextBoxAdapter.cs
- CommandBinding.cs
- ArrayTypeMismatchException.cs
- TextFindEngine.cs
- XmlSchemaGroup.cs
- PropertyDescriptorCollection.cs
- CopyOfAction.cs
- CacheMemory.cs
- SpinWait.cs
- ApplicationDirectory.cs
- AlternateView.cs
- CookieProtection.cs
- GacUtil.cs
- ActivityTypeDesigner.xaml.cs
- BamlRecordWriter.cs
- IntegerValidator.cs
- NativeMethods.cs
- EastAsianLunisolarCalendar.cs
- FormView.cs
- SimpleExpression.cs
- HtmlWindowCollection.cs
- XmlBinaryReader.cs
- DataGridAutoFormat.cs
- NativeRecognizer.cs
- TextEditorParagraphs.cs
- LiteralControl.cs
- AccessibilityHelperForVista.cs
- SynchronizedPool.cs
- ExpressionPrefixAttribute.cs
- OutputScope.cs
- Pkcs7Recipient.cs
- HeaderedItemsControl.cs
- TypeDescriptorContext.cs
- WebHttpDispatchOperationSelector.cs
- EntryIndex.cs
- PartitionerStatic.cs
- InputMethodStateTypeInfo.cs
- DataListCommandEventArgs.cs
- InputManager.cs
- LicFileLicenseProvider.cs
- GridViewColumnHeaderAutomationPeer.cs
- ContactManager.cs
- AdornedElementPlaceholder.cs
- EditorZoneAutoFormat.cs
- TextBoxLine.cs
- regiisutil.cs
- SqlTypeConverter.cs
- BulletChrome.cs
- BulletedListEventArgs.cs
- PropertyRef.cs
- LockCookie.cs
- ErrorStyle.cs
- SystemIPAddressInformation.cs
- SqlUserDefinedAggregateAttribute.cs
- GridErrorDlg.cs
- CharEntityEncoderFallback.cs
- WindowsToolbarAsMenu.cs
- Baml2006KnownTypes.cs
- TableParagraph.cs
- AndCondition.cs
- NativeMethods.cs
- TypeReference.cs
- ListSourceHelper.cs
- Span.cs
- DataSourceIDConverter.cs
- CheckBoxField.cs
- ExpressionEditorSheet.cs
- AsyncResult.cs
- ReadOnlyCollectionBase.cs
- ProfileServiceManager.cs
- RadioButton.cs
- WindowsPrincipal.cs