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
- WindowsImpersonationContext.cs
- ImageKeyConverter.cs
- AddressUtility.cs
- SelectionListComponentEditor.cs
- GridSplitter.cs
- NavigationProgressEventArgs.cs
- OAVariantLib.cs
- SafeNativeMethods.cs
- InputManager.cs
- AssociationSet.cs
- FixedElement.cs
- XmlSchemaCollection.cs
- EntityDataSourceWrapperCollection.cs
- WebPartDeleteVerb.cs
- WebSysDisplayNameAttribute.cs
- InvalidPropValue.cs
- TransactionFilter.cs
- ModelPropertyImpl.cs
- MulticastDelegate.cs
- ValidationEventArgs.cs
- WebMethodAttribute.cs
- DbSetClause.cs
- TabControl.cs
- ListViewCommandEventArgs.cs
- WindowsScroll.cs
- CodeExpressionStatement.cs
- OdbcFactory.cs
- EmptyControlCollection.cs
- WsdlImporterElement.cs
- DesignerSelectionListAdapter.cs
- GetPageCompletedEventArgs.cs
- TraceListener.cs
- DoubleAnimation.cs
- RegexTree.cs
- ProviderException.cs
- RoleManagerSection.cs
- indexingfiltermarshaler.cs
- QuotedPrintableStream.cs
- KnownBoxes.cs
- _BaseOverlappedAsyncResult.cs
- HttpWebRequest.cs
- AssertFilter.cs
- DataStreams.cs
- AlignmentXValidation.cs
- SqlConnectionFactory.cs
- WebColorConverter.cs
- MobileFormsAuthentication.cs
- BuildTopDownAttribute.cs
- Console.cs
- ConstantSlot.cs
- ParserStreamGeometryContext.cs
- DataReaderContainer.cs
- SQLInt32Storage.cs
- HighContrastHelper.cs
- SettingsSection.cs
- ByteStorage.cs
- OpCodes.cs
- ValueOfAction.cs
- QuotedPrintableStream.cs
- MouseEvent.cs
- DragEvent.cs
- BlockUIContainer.cs
- ProcessStartInfo.cs
- ReverseInheritProperty.cs
- XmlSchemaRedefine.cs
- ConvertersCollection.cs
- StructureChangedEventArgs.cs
- NamedElement.cs
- ChangeProcessor.cs
- XmlException.cs
- ContentDisposition.cs
- PeerInvitationResponse.cs
- Int16.cs
- DataFormat.cs
- TransactionChannelFaultConverter.cs
- DecoderBestFitFallback.cs
- FamilyMap.cs
- DesignerHelpers.cs
- GridItemCollection.cs
- EventToken.cs
- PathSegment.cs
- AsymmetricAlgorithm.cs
- SqlCacheDependencySection.cs
- RegisteredHiddenField.cs
- ParameterCollection.cs
- AsyncResult.cs
- DynamicQueryStringParameter.cs
- XmlWriterTraceListener.cs
- FileSystemEventArgs.cs
- WebBrowser.cs
- JsonServiceDocumentSerializer.cs
- ResourceWriter.cs
- cookiecontainer.cs
- AdornerDecorator.cs
- AccessDataSource.cs
- SamlAuthenticationStatement.cs
- UpdateDelegates.Generated.cs
- ScrollData.cs
- TypeForwardedToAttribute.cs
- AddInPipelineAttributes.cs