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
- diagnosticsswitches.cs
- DataServiceSaveChangesEventArgs.cs
- ConfigurationManagerInternalFactory.cs
- DataFieldConverter.cs
- SQLByte.cs
- SamlSerializer.cs
- ResourcesChangeInfo.cs
- DataGridViewDataConnection.cs
- TrustManager.cs
- CrossSiteScriptingValidation.cs
- PackagePart.cs
- FrameworkElement.cs
- HandleRef.cs
- XsdBuilder.cs
- AcceleratedTokenAuthenticator.cs
- PenThreadPool.cs
- CompiledQueryCacheKey.cs
- DataRecordObjectView.cs
- CorrelationToken.cs
- PlacementWorkspace.cs
- DataTableTypeConverter.cs
- DataGridViewComboBoxColumn.cs
- TdsParserHelperClasses.cs
- CardSpaceShim.cs
- CacheAxisQuery.cs
- Pens.cs
- ComponentDispatcherThread.cs
- NamespaceCollection.cs
- ThicknessAnimation.cs
- AsymmetricAlgorithm.cs
- FloaterParagraph.cs
- ManagedWndProcTracker.cs
- SettingsPropertyValue.cs
- SQLMoneyStorage.cs
- ContextStaticAttribute.cs
- CodeChecksumPragma.cs
- ExpressionBinding.cs
- RectIndependentAnimationStorage.cs
- AutomationFocusChangedEventArgs.cs
- BindingList.cs
- Cursor.cs
- FactoryGenerator.cs
- JournalEntry.cs
- EngineSiteSapi.cs
- PenThreadPool.cs
- CellQuery.cs
- Normalization.cs
- FixedDocument.cs
- VisualTreeUtils.cs
- MinMaxParagraphWidth.cs
- ActivityDelegate.cs
- InternalCompensate.cs
- SrgsElementFactoryCompiler.cs
- ConnectionPoint.cs
- PersonalizationDictionary.cs
- ParallelTimeline.cs
- RestHandler.cs
- LabelTarget.cs
- ShaderRenderModeValidation.cs
- ApplicationGesture.cs
- BuildProvider.cs
- PackWebRequestFactory.cs
- TemplatingOptionsDialog.cs
- CodeExporter.cs
- OLEDB_Enum.cs
- PreviousTrackingServiceAttribute.cs
- GeometryGroup.cs
- Message.cs
- IListConverters.cs
- AuthenticationSection.cs
- StylusPointPropertyUnit.cs
- TableLayoutColumnStyleCollection.cs
- ReadOnlyObservableCollection.cs
- TemplatedMailWebEventProvider.cs
- PersonalizationStateInfoCollection.cs
- OdbcErrorCollection.cs
- shaper.cs
- Automation.cs
- DLinqColumnProvider.cs
- EntityDescriptor.cs
- AnnotationService.cs
- GridEntry.cs
- RoutedPropertyChangedEventArgs.cs
- LayoutTable.cs
- DataGridRowDetailsEventArgs.cs
- milexports.cs
- RenderData.cs
- Int64.cs
- DependencyObjectProvider.cs
- Config.cs
- WindowsListViewScroll.cs
- LayoutInformation.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- XmlWriter.cs
- ConfigurationCollectionAttribute.cs
- Transform3D.cs
- ScriptManager.cs
- DataServiceClientException.cs
- HtmlElementEventArgs.cs
- TextParagraphView.cs