Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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 sync 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; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PaintEvent.cs
- CreatingCookieEventArgs.cs
- ExeConfigurationFileMap.cs
- CodeCatchClauseCollection.cs
- UriSchemeKeyedCollection.cs
- SQLInt32.cs
- CaseCqlBlock.cs
- DashStyles.cs
- MetadataArtifactLoaderCompositeFile.cs
- ConditionalAttribute.cs
- CompoundFileDeflateTransform.cs
- XpsDocument.cs
- PropertyInformation.cs
- StylusLogic.cs
- CustomAttributeBuilder.cs
- DiscoveryOperationContext.cs
- Polygon.cs
- XslTransformFileEditor.cs
- UserControl.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- WebPartPersonalization.cs
- CompensationParticipant.cs
- Int64AnimationUsingKeyFrames.cs
- SchemaInfo.cs
- CompilerWrapper.cs
- TextBounds.cs
- XMLSchema.cs
- WebMessageBodyStyleHelper.cs
- IUnknownConstantAttribute.cs
- ElementHostAutomationPeer.cs
- DataRelationCollection.cs
- FrameDimension.cs
- Currency.cs
- SchemaCollectionPreprocessor.cs
- HttpApplicationFactory.cs
- FontCollection.cs
- SystemException.cs
- NamedPipeChannelFactory.cs
- CookieParameter.cs
- XPathSingletonIterator.cs
- ParameterToken.cs
- ExtentKey.cs
- WebScriptServiceHostFactory.cs
- HttpGetServerProtocol.cs
- VoiceChangeEventArgs.cs
- DSACryptoServiceProvider.cs
- Matrix3D.cs
- Stack.cs
- WmpBitmapDecoder.cs
- DataColumn.cs
- ShapeTypeface.cs
- ProbeMatchesMessageCD1.cs
- BufferedReadStream.cs
- RuntimeConfigurationRecord.cs
- activationcontext.cs
- SettingsProperty.cs
- CacheVirtualItemsEvent.cs
- AppSettingsReader.cs
- ImageMetadata.cs
- FrameworkContentElementAutomationPeer.cs
- FrameworkContentElement.cs
- ConversionContext.cs
- ResXBuildProvider.cs
- ConsumerConnectionPoint.cs
- GPRECT.cs
- RSAPKCS1SignatureDeformatter.cs
- FontWeightConverter.cs
- ResourcePermissionBaseEntry.cs
- AnnotationHighlightLayer.cs
- ApplicationInfo.cs
- DataRecord.cs
- BamlStream.cs
- Positioning.cs
- DetailsViewRowCollection.cs
- CompositeFontInfo.cs
- DiscoveryDocumentSearchPattern.cs
- EmptyWorkItem.cs
- CaseInsensitiveHashCodeProvider.cs
- Transform.cs
- HScrollBar.cs
- DetailsViewUpdatedEventArgs.cs
- HiddenField.cs
- CellTreeNodeVisitors.cs
- BigIntegerStorage.cs
- WebPartConnectionsDisconnectVerb.cs
- DateTime.cs
- ToolStripLabel.cs
- ColorMatrix.cs
- SpeakInfo.cs
- HostSecurityManager.cs
- XmlNodeList.cs
- StylusButton.cs
- Matrix3DValueSerializer.cs
- ComponentCollection.cs
- EnvironmentPermission.cs
- EditorBrowsableAttribute.cs
- EncoderNLS.cs
- ColorConvertedBitmap.cs
- ConnectionPointGlyph.cs
- DataBinding.cs