Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / AsyncOperation.cs / 1305376 / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LeafCellTreeNode.cs
- ReadOnlyPropertyMetadata.cs
- SQLConvert.cs
- WebSysDescriptionAttribute.cs
- PathSegmentCollection.cs
- ThreadSafeList.cs
- MasterPageParser.cs
- WebPartConnectionsConnectVerb.cs
- XMLDiffLoader.cs
- ContainerCodeDomSerializer.cs
- XmlWriterDelegator.cs
- WebHttpEndpointElement.cs
- ByteStorage.cs
- SQLMembershipProvider.cs
- HwndSubclass.cs
- OdbcConnectionHandle.cs
- TransformerInfo.cs
- SocketException.cs
- CorrelationKey.cs
- FolderNameEditor.cs
- NavigationHelper.cs
- DataRowChangeEvent.cs
- StaticSiteMapProvider.cs
- KeyGestureValueSerializer.cs
- System.Data_BID.cs
- DurableInstanceProvider.cs
- ParserStreamGeometryContext.cs
- UrlMappingCollection.cs
- AsyncPostBackErrorEventArgs.cs
- LeaseManager.cs
- SizeConverter.cs
- XmlSerializationWriter.cs
- TransactionCache.cs
- NameValueConfigurationElement.cs
- CanonicalizationDriver.cs
- RectangleHotSpot.cs
- InputManager.cs
- SecurityManager.cs
- RuntimeConfigLKG.cs
- ErrorRuntimeConfig.cs
- DBConnection.cs
- MediaPlayer.cs
- SignedInfo.cs
- DockProviderWrapper.cs
- WebPartConnectionsConfigureVerb.cs
- PropertyMetadata.cs
- LinearGradientBrush.cs
- SecUtil.cs
- SqlNode.cs
- AppDomainManager.cs
- DashStyle.cs
- ExtensionDataReader.cs
- ReflectionUtil.cs
- ConditionalWeakTable.cs
- XmlUtilWriter.cs
- Int64AnimationUsingKeyFrames.cs
- AdapterDictionary.cs
- XmlCharType.cs
- XmlBinaryReader.cs
- DataRowView.cs
- ScopedKnownTypes.cs
- DuplicateWaitObjectException.cs
- DbDataSourceEnumerator.cs
- GenericAuthenticationEventArgs.cs
- ConfigXmlComment.cs
- InheritablePropertyChangeInfo.cs
- SizeAnimationUsingKeyFrames.cs
- TextElementEnumerator.cs
- BufferBuilder.cs
- XmlIlTypeHelper.cs
- XmlQueryType.cs
- EncodedStreamFactory.cs
- DbBuffer.cs
- EncoderParameters.cs
- FormView.cs
- TempFiles.cs
- ToolZone.cs
- Tile.cs
- StylusPointDescription.cs
- Attributes.cs
- TextRangeEditTables.cs
- RegisterResponseInfo.cs
- WebBrowserBase.cs
- WebPartUserCapability.cs
- GB18030Encoding.cs
- ExpandSegmentCollection.cs
- Style.cs
- ImageListUtils.cs
- WebPartTracker.cs
- SiteMapDataSourceView.cs
- Constraint.cs
- ObjectTag.cs
- SerializationHelper.cs
- ToggleButton.cs
- OrderedDictionary.cs
- EntityContainerRelationshipSetEnd.cs
- SqlMultiplexer.cs
- SvcMapFileSerializer.cs
- RedirectionProxy.cs
- InternalMappingException.cs