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
- PropertyMap.cs
- DeclarativeCatalogPart.cs
- Translator.cs
- WorkflowApplicationCompletedEventArgs.cs
- HttpListenerResponse.cs
- FSWPathEditor.cs
- Variant.cs
- mediaeventargs.cs
- ObjectKeyFrameCollection.cs
- InstanceNotReadyException.cs
- PropertyPathWorker.cs
- QilInvoke.cs
- MultiView.cs
- InstanceDataCollection.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- TypeDelegator.cs
- DataGridCommandEventArgs.cs
- LabelEditEvent.cs
- Container.cs
- OleDbEnumerator.cs
- ButtonChrome.cs
- CodeNamespaceImport.cs
- AttachInfo.cs
- BuiltInPermissionSets.cs
- HashUtility.cs
- ObjectListField.cs
- DataGridColumn.cs
- codemethodreferenceexpression.cs
- Message.cs
- BitmapMetadataEnumerator.cs
- Screen.cs
- RuleConditionDialog.cs
- ExecutionContext.cs
- TreeBuilderXamlTranslator.cs
- XPathNavigatorReader.cs
- BindingContext.cs
- QilVisitor.cs
- PathFigure.cs
- RoleManagerSection.cs
- InputManager.cs
- RepeatButton.cs
- XmlIgnoreAttribute.cs
- ServiceOperationWrapper.cs
- TimerEventSubscriptionCollection.cs
- CryptoApi.cs
- AssemblyInfo.cs
- ImmComposition.cs
- ConfigXmlElement.cs
- NamespaceDecl.cs
- DbConnectionStringBuilder.cs
- ThreadStateException.cs
- WindowsHyperlink.cs
- SoapAttributes.cs
- TypographyProperties.cs
- ManagementObjectSearcher.cs
- SessionEndingCancelEventArgs.cs
- TextRunCache.cs
- XmlObjectSerializerReadContextComplex.cs
- WorkflowInstanceContextProvider.cs
- MimeFormReflector.cs
- ManipulationDeltaEventArgs.cs
- UserInitiatedNavigationPermission.cs
- CapabilitiesState.cs
- LoginCancelEventArgs.cs
- XmlNode.cs
- SchemaCollectionCompiler.cs
- BinaryCommonClasses.cs
- MediaContextNotificationWindow.cs
- EdmMember.cs
- ProjectionAnalyzer.cs
- ObjectAnimationBase.cs
- ResourceAssociationType.cs
- BinaryMessageFormatter.cs
- SrgsElementFactory.cs
- Rule.cs
- SafeSerializationManager.cs
- COM2Enum.cs
- SelectionListComponentEditor.cs
- RelationshipFixer.cs
- DbMetaDataColumnNames.cs
- Predicate.cs
- CodeGroup.cs
- ListQueryResults.cs
- SimpleHandlerBuildProvider.cs
- ReferenceSchema.cs
- CommonObjectSecurity.cs
- SRDisplayNameAttribute.cs
- ScriptServiceAttribute.cs
- DynamicObjectAccessor.cs
- MappingModelBuildProvider.cs
- UnicodeEncoding.cs
- ELinqQueryState.cs
- CssClassPropertyAttribute.cs
- Int16AnimationUsingKeyFrames.cs
- SelectionWordBreaker.cs
- InfoCardArgumentException.cs
- MULTI_QI.cs
- CustomValidator.cs
- DeploymentSectionCache.cs
- WebConfigurationFileMap.cs