Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ //// 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
- PathData.cs
- DesignerRegion.cs
- InlinedAggregationOperator.cs
- VBIdentifierName.cs
- WindowsGraphicsCacheManager.cs
- DiagnosticsConfigurationHandler.cs
- DataGridCellsPanel.cs
- PackageDigitalSignatureManager.cs
- KeyFrames.cs
- HotCommands.cs
- RevocationPoint.cs
- Int32AnimationUsingKeyFrames.cs
- wgx_sdk_version.cs
- ProtocolsConfiguration.cs
- DataSetUtil.cs
- TableDesigner.cs
- SubclassTypeValidator.cs
- CacheHelper.cs
- SimpleFileLog.cs
- ObjectDataSourceEventArgs.cs
- BamlStream.cs
- _DigestClient.cs
- SqlDataSourceStatusEventArgs.cs
- ByteStorage.cs
- SoapDocumentMethodAttribute.cs
- IncrementalReadDecoders.cs
- MessageBox.cs
- ObjectViewEntityCollectionData.cs
- OdbcPermission.cs
- UDPClient.cs
- PasswordBoxAutomationPeer.cs
- DeclaredTypeElement.cs
- RegisteredDisposeScript.cs
- HtmlMeta.cs
- MemberInfoSerializationHolder.cs
- TextTreeTextNode.cs
- ScaleTransform.cs
- ParserContext.cs
- WebSysDescriptionAttribute.cs
- NavigationPropertyEmitter.cs
- RemotingConfigParser.cs
- PathNode.cs
- WorkflowQueuingService.cs
- PropertyGridView.cs
- ApplicationSecurityInfo.cs
- SHA384CryptoServiceProvider.cs
- PolicyException.cs
- TileModeValidation.cs
- CachedFontFamily.cs
- SudsParser.cs
- IPAddressCollection.cs
- ServiceEndpoint.cs
- ByteStorage.cs
- FrameworkTextComposition.cs
- SystemNetHelpers.cs
- PropertyGridCommands.cs
- ProcessHostMapPath.cs
- DecoderFallbackWithFailureFlag.cs
- CompilerTypeWithParams.cs
- HMACSHA256.cs
- DataListItemEventArgs.cs
- DbParameterCollectionHelper.cs
- DecoratedNameAttribute.cs
- StaticResourceExtension.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- EDesignUtil.cs
- CompletionCallbackWrapper.cs
- ExpressionPrefixAttribute.cs
- ArrayTypeMismatchException.cs
- RequestCacheEntry.cs
- ToolStripOverflow.cs
- WindowsListViewItemStartMenu.cs
- DebugView.cs
- ExecutionContext.cs
- CompareInfo.cs
- SrgsNameValueTag.cs
- ScaleTransform3D.cs
- OpenTypeCommon.cs
- AsyncPostBackTrigger.cs
- GenericArgumentsUpdater.cs
- RelationshipConstraintValidator.cs
- SqlDataSourceRefreshSchemaForm.cs
- UnionCqlBlock.cs
- ScriptServiceAttribute.cs
- AppDomainFactory.cs
- UpdateManifestForBrowserApplication.cs
- ConfigXmlWhitespace.cs
- GroupDescription.cs
- SoapConverter.cs
- TypeDescriptionProvider.cs
- FreezableCollection.cs
- RegexGroupCollection.cs
- Double.cs
- Activator.cs
- ScaleTransform.cs
- FolderBrowserDialogDesigner.cs
- TreeViewImageIndexConverter.cs
- VirtualizingPanel.cs
- EventToken.cs
- StreamAsIStream.cs