Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CompMod / System / ComponentModel / AsyncOperation.cs / 1 / AsyncOperation.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.ComponentModel { using System.Security.Permissions; using System.Threading; [HostProtection(SharedState = true)] public sealed class AsyncOperation { private SynchronizationContext syncContext; private object userSuppliedState; private bool alreadyCompleted; ////// Constructor. Protected to avoid unwitting usage - AsyncOperation objects /// are typically created by AsyncOperationManager calling CreateOperation. /// private AsyncOperation(object userSuppliedState, SynchronizationContext syncContext) { this.userSuppliedState = userSuppliedState; this.syncContext = syncContext; this.alreadyCompleted = false; this.syncContext.OperationStarted(); } ////// Destructor. Guarantees that [....] context will always get notified of completion. /// ~AsyncOperation() { if (!alreadyCompleted && syncContext != null) { syncContext.OperationCompleted(); } } public object UserSuppliedState { get { return userSuppliedState; } } ///public SynchronizationContext SynchronizationContext { get { return syncContext; } } public void Post(SendOrPostCallback d, object arg) { VerifyNotCompleted(); VerifyDelegateNotNull(d); syncContext.Post(d, arg); } public void PostOperationCompleted(SendOrPostCallback d, object arg) { Post(d, arg); OperationCompletedCore(); } public void OperationCompleted() { VerifyNotCompleted(); OperationCompletedCore(); } private void OperationCompletedCore() { try { syncContext.OperationCompleted(); } finally { alreadyCompleted = true; GC.SuppressFinalize(this); } } private void VerifyNotCompleted() { if (alreadyCompleted) { throw new InvalidOperationException(SR.GetString(SR.Async_OperationAlreadyCompleted)); } } private void VerifyDelegateNotNull(SendOrPostCallback d) { if (d == null) { throw new ArgumentNullException(SR.GetString(SR.Async_NullDelegate), "d"); } } /// /// Only for use by AsyncOperationManager to create new AsyncOperation objects /// internal static AsyncOperation CreateOperation(object userSuppliedState, SynchronizationContext syncContext) { AsyncOperation newOp = new AsyncOperation(userSuppliedState, syncContext); return newOp; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.ComponentModel { using System.Security.Permissions; using System.Threading; [HostProtection(SharedState = true)] public sealed class AsyncOperation { private SynchronizationContext syncContext; private object userSuppliedState; private bool alreadyCompleted; ////// Constructor. Protected to avoid unwitting usage - AsyncOperation objects /// are typically created by AsyncOperationManager calling CreateOperation. /// private AsyncOperation(object userSuppliedState, SynchronizationContext syncContext) { this.userSuppliedState = userSuppliedState; this.syncContext = syncContext; this.alreadyCompleted = false; this.syncContext.OperationStarted(); } ////// Destructor. Guarantees that [....] context will always get notified of completion. /// ~AsyncOperation() { if (!alreadyCompleted && syncContext != null) { syncContext.OperationCompleted(); } } public object UserSuppliedState { get { return userSuppliedState; } } ///public SynchronizationContext SynchronizationContext { get { return syncContext; } } public void Post(SendOrPostCallback d, object arg) { VerifyNotCompleted(); VerifyDelegateNotNull(d); syncContext.Post(d, arg); } public void PostOperationCompleted(SendOrPostCallback d, object arg) { Post(d, arg); OperationCompletedCore(); } public void OperationCompleted() { VerifyNotCompleted(); OperationCompletedCore(); } private void OperationCompletedCore() { try { syncContext.OperationCompleted(); } finally { alreadyCompleted = true; GC.SuppressFinalize(this); } } private void VerifyNotCompleted() { if (alreadyCompleted) { throw new InvalidOperationException(SR.GetString(SR.Async_OperationAlreadyCompleted)); } } private void VerifyDelegateNotNull(SendOrPostCallback d) { if (d == null) { throw new ArgumentNullException(SR.GetString(SR.Async_NullDelegate), "d"); } } /// /// Only for use by AsyncOperationManager to create new AsyncOperation objects /// internal static AsyncOperation CreateOperation(object userSuppliedState, SynchronizationContext syncContext) { AsyncOperation newOp = new AsyncOperation(userSuppliedState, syncContext); return newOp; } } } // 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
- SqlBinder.cs
- ControlBuilder.cs
- IgnoreFileBuildProvider.cs
- COM2ExtendedTypeConverter.cs
- Viewport3DVisual.cs
- XmlSecureResolver.cs
- PageRequestManager.cs
- SoapAttributes.cs
- DomainConstraint.cs
- TextEffectResolver.cs
- UIElementHelper.cs
- __TransparentProxy.cs
- JumpTask.cs
- OdbcCommandBuilder.cs
- CodeAttributeDeclarationCollection.cs
- IDispatchConstantAttribute.cs
- DiscreteKeyFrames.cs
- ViewRendering.cs
- DataSourceXmlClassAttribute.cs
- SoundPlayer.cs
- IListConverters.cs
- DbDeleteCommandTree.cs
- ShortcutKeysEditor.cs
- RoleGroupCollection.cs
- LogEntryHeaderSerializer.cs
- PolygonHotSpot.cs
- RegexCompilationInfo.cs
- Pkcs7Signer.cs
- DataGridViewAddColumnDialog.cs
- CodeGeneratorOptions.cs
- SafeFileHandle.cs
- LayoutEngine.cs
- QueryParameter.cs
- HttpListenerException.cs
- ControlLocalizer.cs
- DataGridViewTopLeftHeaderCell.cs
- Triplet.cs
- ObjectDataSource.cs
- HttpListenerPrefixCollection.cs
- NullReferenceException.cs
- DrawingBrush.cs
- DataBindingCollectionEditor.cs
- TypeValidationEventArgs.cs
- DataSysAttribute.cs
- Timeline.cs
- AuthenticateEventArgs.cs
- Variable.cs
- arabicshape.cs
- ReadOnlyDictionary.cs
- CryptoApi.cs
- StrokeSerializer.cs
- AlignmentXValidation.cs
- MetafileHeaderWmf.cs
- NullNotAllowedCollection.cs
- ObjectListItemCollection.cs
- WaitForChangedResult.cs
- WebServiceData.cs
- HttpContext.cs
- SQLInt64.cs
- BitmapSizeOptions.cs
- GeometryHitTestParameters.cs
- InternalSafeNativeMethods.cs
- HtmlInputRadioButton.cs
- ParameterDataSourceExpression.cs
- ServiceDescriptionSerializer.cs
- QueryContinueDragEvent.cs
- ToolStripDesignerUtils.cs
- WindowsGraphics2.cs
- UserControlAutomationPeer.cs
- DrawingDrawingContext.cs
- RightsManagementEncryptionTransform.cs
- HtmlControlDesigner.cs
- EventSetterHandlerConverter.cs
- PKCS1MaskGenerationMethod.cs
- ObjectRef.cs
- DbResourceAllocator.cs
- PointLightBase.cs
- AvTrace.cs
- EncodingDataItem.cs
- RoutingUtilities.cs
- CompositeDuplexBindingElement.cs
- XmlSchemaObjectTable.cs
- InputLanguageSource.cs
- RegexTypeEditor.cs
- ToolStripGrip.cs
- Rect3D.cs
- XmlResolver.cs
- SqlTypesSchemaImporter.cs
- Rect3DConverter.cs
- ProfileSettingsCollection.cs
- QueryRewriter.cs
- LeftCellWrapper.cs
- GeneralTransform.cs
- ThemeInfoAttribute.cs
- DataGridHyperlinkColumn.cs
- PackagePart.cs
- DataGridViewComboBoxEditingControl.cs
- ToolboxItemFilterAttribute.cs
- WeakRefEnumerator.cs
- VisualBrush.cs