Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- RowSpanVector.cs
- IndependentAnimationStorage.cs
- CompilerLocalReference.cs
- HttpCookie.cs
- PeerEndPoint.cs
- ListContractAdapter.cs
- WmlValidationSummaryAdapter.cs
- BackgroundFormatInfo.cs
- CollectionsUtil.cs
- QueuedDeliveryRequirementsMode.cs
- UnsafeNativeMethods.cs
- GenericIdentity.cs
- UnsafeNativeMethods.cs
- RefExpr.cs
- MDIWindowDialog.cs
- OleDbPermission.cs
- DataRecordObjectView.cs
- AnnotationComponentManager.cs
- BuilderInfo.cs
- SqlFileStream.cs
- RefreshPropertiesAttribute.cs
- DataGridViewTextBoxCell.cs
- ValidatorCompatibilityHelper.cs
- WebServiceAttribute.cs
- CustomSignedXml.cs
- WindowsStatic.cs
- DataBinder.cs
- ProcessProtocolHandler.cs
- SQLChars.cs
- TransactionOptions.cs
- Domain.cs
- CssTextWriter.cs
- DbBuffer.cs
- Lasso.cs
- PatternMatcher.cs
- Switch.cs
- XmlSchemaValidationException.cs
- StylusLogic.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- LineProperties.cs
- Point3DAnimation.cs
- Attribute.cs
- DirectionalLight.cs
- DockPattern.cs
- DragSelectionMessageFilter.cs
- SpanIndex.cs
- AccessorTable.cs
- NamespaceExpr.cs
- fixedPageContentExtractor.cs
- EntityTypeBase.cs
- ListViewGroupConverter.cs
- ErrorLog.cs
- BasicSecurityProfileVersion.cs
- Win32Native.cs
- DataServiceHostFactory.cs
- Material.cs
- DesignerRegion.cs
- CompilationUnit.cs
- DirtyTextRange.cs
- SimpleApplicationHost.cs
- XPathPatternBuilder.cs
- HttpMethodAttribute.cs
- odbcmetadatacollectionnames.cs
- SyntaxCheck.cs
- BCLDebug.cs
- Rect.cs
- TableLayoutStyle.cs
- AssemblyUtil.cs
- ConfigurationPropertyAttribute.cs
- PassportAuthentication.cs
- XmlSchemaSimpleType.cs
- XmlSerializerNamespaces.cs
- DiscoveryClientChannelBase.cs
- ObjectIDGenerator.cs
- GridSplitter.cs
- ClientRoleProvider.cs
- MouseEvent.cs
- FixedPage.cs
- BufferedGraphicsContext.cs
- DependencyPropertyHelper.cs
- ComPersistableTypeElementCollection.cs
- ProcessHostConfigUtils.cs
- UrlMappingsSection.cs
- BaseDataList.cs
- TypeConverterAttribute.cs
- SessionChannels.cs
- ErrorProvider.cs
- Listener.cs
- ping.cs
- MimeParameter.cs
- ProcessThread.cs
- WebPartsPersonalizationAuthorization.cs
- LocalValueEnumerator.cs
- LazyTextWriterCreator.cs
- DateTimeFormatInfoScanner.cs
- SingleKeyFrameCollection.cs
- ReadContentAsBinaryHelper.cs
- FollowerQueueCreator.cs
- WebPartConnectionsCloseVerb.cs
- CollectionAdapters.cs