Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ToolStripLabel.cs
- FormsAuthentication.cs
- HtmlElementEventArgs.cs
- ExternalException.cs
- DataControlButton.cs
- JsonWriterDelegator.cs
- WindowsScrollBar.cs
- DbConnectionOptions.cs
- SetterBaseCollection.cs
- Application.cs
- EdmValidator.cs
- ArithmeticException.cs
- WebPartRestoreVerb.cs
- OracleException.cs
- ServiceNameCollection.cs
- Vector3DAnimation.cs
- ProfileManager.cs
- Registry.cs
- TokenizerHelper.cs
- EntityParameter.cs
- BreakSafeBase.cs
- SqlDependency.cs
- ServiceDesigner.xaml.cs
- WebSysDisplayNameAttribute.cs
- PagedDataSource.cs
- MsmqIntegrationChannelListener.cs
- DocumentViewerBase.cs
- IListConverters.cs
- NotificationContext.cs
- BitmapEffectDrawingContextState.cs
- DataRowCollection.cs
- ComMethodElement.cs
- CodeSnippetCompileUnit.cs
- DataGridParentRows.cs
- InvalidCastException.cs
- XhtmlBasicCommandAdapter.cs
- IIS7UserPrincipal.cs
- RequestCacheManager.cs
- ListBoxItemAutomationPeer.cs
- TextFormatterContext.cs
- WmpBitmapDecoder.cs
- ItemsChangedEventArgs.cs
- PropertyGroupDescription.cs
- PathSegmentCollection.cs
- DecimalConstantAttribute.cs
- ProcessingInstructionAction.cs
- DetectEofStream.cs
- EditorAttribute.cs
- EmbossBitmapEffect.cs
- MsmqTransportElement.cs
- DisposableCollectionWrapper.cs
- InstanceKeyView.cs
- SoapEnumAttribute.cs
- BindingCollectionElement.cs
- ResourceFallbackManager.cs
- MouseButton.cs
- SafeThreadHandle.cs
- ImageIndexConverter.cs
- SecurityException.cs
- ConsoleKeyInfo.cs
- HealthMonitoringSectionHelper.cs
- PartialClassGenerationTaskInternal.cs
- x509store.cs
- ConnectionPoolManager.cs
- PropertyChangedEventManager.cs
- SimpleWorkerRequest.cs
- WebPartEditorCancelVerb.cs
- StateMachineHelpers.cs
- GPPOINT.cs
- FileRegion.cs
- FigureParagraph.cs
- NetMsmqSecurity.cs
- GridViewRowCollection.cs
- MobileResource.cs
- ProcessingInstructionAction.cs
- BitConverter.cs
- CustomValidator.cs
- ScrollBarRenderer.cs
- ToolBarButtonClickEvent.cs
- MemberListBinding.cs
- HttpTransportManager.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- ArgumentException.cs
- DateRangeEvent.cs
- StorageTypeMapping.cs
- StateDesigner.LayoutSelectionGlyph.cs
- DataServiceExpressionVisitor.cs
- AuthenticationService.cs
- FactoryMaker.cs
- FromReply.cs
- SmiRequestExecutor.cs
- SmiMetaDataProperty.cs
- DSASignatureFormatter.cs
- TraceListeners.cs
- DataError.cs
- XsltContext.cs
- DbProviderFactoriesConfigurationHandler.cs
- Style.cs
- PageParser.cs
- BrowserDefinition.cs