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
- RestClientProxyHandler.cs
- FormatterServices.cs
- WindowsBrush.cs
- FixedSOMSemanticBox.cs
- NTAccount.cs
- RemotingConfiguration.cs
- ExceptionRoutedEventArgs.cs
- TextTreeFixupNode.cs
- SQLInt64.cs
- XmlSchemaCollection.cs
- DBPropSet.cs
- PixelFormatConverter.cs
- HtmlInputPassword.cs
- Transactions.cs
- CannotUnloadAppDomainException.cs
- DataGridViewColumn.cs
- RegularExpressionValidator.cs
- formatter.cs
- CheckBoxField.cs
- EntitySqlQueryCacheKey.cs
- AnonymousIdentificationModule.cs
- SqlIdentifier.cs
- SafeRightsManagementPubHandle.cs
- RelationshipSet.cs
- DataColumnMapping.cs
- HostSecurityManager.cs
- ColumnClickEvent.cs
- ScrollProperties.cs
- SQLInt16.cs
- StorageInfo.cs
- storepermission.cs
- StandardBindingReliableSessionElement.cs
- NotFiniteNumberException.cs
- AttributeCollection.cs
- ProfileSettingsCollection.cs
- DragDropHelper.cs
- PropertyPath.cs
- ThemeConfigurationDialog.cs
- Point.cs
- SQLSingleStorage.cs
- PageAsyncTaskManager.cs
- ModifierKeysConverter.cs
- Pen.cs
- XmlSchemaCollection.cs
- TextServicesDisplayAttributePropertyRanges.cs
- shaperfactoryquerycacheentry.cs
- CanonicalFontFamilyReference.cs
- hwndwrapper.cs
- MonthChangedEventArgs.cs
- InitializerFacet.cs
- WebPart.cs
- XPathSelfQuery.cs
- TextFormatter.cs
- HeaderPanel.cs
- DLinqTableProvider.cs
- ObjectToken.cs
- ClientScriptItem.cs
- TrueReadOnlyCollection.cs
- CheckedListBox.cs
- PatternMatcher.cs
- PreloadedPackages.cs
- SafeLibraryHandle.cs
- InternalUserCancelledException.cs
- RSAPKCS1SignatureFormatter.cs
- LineServicesRun.cs
- DuplicateWaitObjectException.cs
- XmlArrayItemAttribute.cs
- SingleBodyParameterMessageFormatter.cs
- FramingFormat.cs
- TextCompositionManager.cs
- String.cs
- Error.cs
- MsmqMessage.cs
- InvalidPrinterException.cs
- AssemblyBuilder.cs
- TextDocumentView.cs
- OrderByBuilder.cs
- Pool.cs
- ComPlusAuthorization.cs
- HttpProfileGroupBase.cs
- SemanticResolver.cs
- MetadataAssemblyHelper.cs
- SqlException.cs
- MasterPageParser.cs
- OperationFormatter.cs
- LinearGradientBrush.cs
- RequestCachePolicy.cs
- StringDictionary.cs
- Splitter.cs
- GridViewColumnHeader.cs
- StatusBar.cs
- LineGeometry.cs
- SortQueryOperator.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- PopupRootAutomationPeer.cs
- ConnectionInterfaceCollection.cs
- FileDialogPermission.cs
- OutputWindow.cs
- CommandHelper.cs
- DbConvert.cs