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
- XmlDataSourceNodeDescriptor.cs
- DataGridViewCellStyleEditor.cs
- XmlSignatureManifest.cs
- SamlAction.cs
- FontDriver.cs
- DivideByZeroException.cs
- RSAOAEPKeyExchangeDeformatter.cs
- DelegatingHeader.cs
- KeysConverter.cs
- _ScatterGatherBuffers.cs
- WindowsListViewSubItem.cs
- GlyphManager.cs
- XamlSerializationHelper.cs
- HandlerFactoryWrapper.cs
- URIFormatException.cs
- UIElementAutomationPeer.cs
- InternalsVisibleToAttribute.cs
- WindowsTokenRoleProvider.cs
- brushes.cs
- StdValidatorsAndConverters.cs
- KeyValueInternalCollection.cs
- AttachmentCollection.cs
- TraceSource.cs
- Identifier.cs
- TransportSecurityProtocol.cs
- GroupBox.cs
- InkCanvasSelectionAdorner.cs
- DbConnectionOptions.cs
- WaitHandleCannotBeOpenedException.cs
- StorageAssociationTypeMapping.cs
- DataSetMappper.cs
- DivideByZeroException.cs
- uribuilder.cs
- Bidi.cs
- SendActivityValidator.cs
- DefaultAutoFieldGenerator.cs
- ZoneIdentityPermission.cs
- WebPartManager.cs
- SqlCacheDependency.cs
- Table.cs
- AssemblyName.cs
- LinkedList.cs
- WinFormsComponentEditor.cs
- InvalidateEvent.cs
- DelayDesigner.cs
- ConfigurationSection.cs
- BamlLocalizableResourceKey.cs
- InternalEnumValidatorAttribute.cs
- XsltLibrary.cs
- PropertiesTab.cs
- SymbolType.cs
- TdsValueSetter.cs
- LayoutEditorPart.cs
- TemplateControl.cs
- ResXResourceSet.cs
- ConnectionConsumerAttribute.cs
- HttpListenerPrefixCollection.cs
- ComPersistableTypeElementCollection.cs
- Inline.cs
- StrokeCollectionDefaultValueFactory.cs
- LeaseManager.cs
- HttpValueCollection.cs
- BindingsCollection.cs
- EntityProviderServices.cs
- CreateCardRequest.cs
- EventWaitHandle.cs
- Nullable.cs
- DoubleLinkListEnumerator.cs
- ArcSegment.cs
- UInt64.cs
- ProvidePropertyAttribute.cs
- RemotingException.cs
- PinProtectionHelper.cs
- XmlQualifiedName.cs
- Monitor.cs
- CodeDefaultValueExpression.cs
- Int32EqualityComparer.cs
- TimeZone.cs
- ProfilePropertyNameValidator.cs
- RuntimeConfigurationRecord.cs
- CaseExpr.cs
- AnnotationHighlightLayer.cs
- sqlnorm.cs
- HostingPreferredMapPath.cs
- assertwrapper.cs
- TcpClientChannel.cs
- MouseDevice.cs
- JpegBitmapDecoder.cs
- XmlLinkedNode.cs
- ConnectionProviderAttribute.cs
- XmlArrayItemAttributes.cs
- ChildTable.cs
- XmlElement.cs
- XMLDiffLoader.cs
- VoiceInfo.cs
- CodeIndexerExpression.cs
- ValueQuery.cs
- FixedSOMTableRow.cs
- PnrpPermission.cs
- InputLanguageProfileNotifySink.cs