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
- SoapSchemaImporter.cs
- PropertyGridView.cs
- EditingMode.cs
- Paragraph.cs
- XDeferredAxisSource.cs
- BitArray.cs
- SimpleType.cs
- WebPartTransformerCollection.cs
- NetSectionGroup.cs
- EmptyEnumerator.cs
- AuthenticationSection.cs
- StyleCollection.cs
- DataViewManager.cs
- KeyedHashAlgorithm.cs
- CommandEventArgs.cs
- BinaryObjectInfo.cs
- HMAC.cs
- CustomErrorsSection.cs
- XmlSchemaSubstitutionGroup.cs
- Stylus.cs
- BuilderPropertyEntry.cs
- ProxySimple.cs
- EntityParameter.cs
- Image.cs
- UserControl.cs
- SettingsContext.cs
- Soap12ProtocolReflector.cs
- XmlAnyElementAttributes.cs
- StringUtil.cs
- MessageBox.cs
- Message.cs
- HttpInputStream.cs
- WindowsListViewGroupSubsetLink.cs
- WebCategoryAttribute.cs
- SmiXetterAccessMap.cs
- Axis.cs
- HttpPostProtocolImporter.cs
- AnnotationAuthorChangedEventArgs.cs
- SqlCharStream.cs
- _TransmitFileOverlappedAsyncResult.cs
- Logging.cs
- AmbientLight.cs
- FrameSecurityDescriptor.cs
- HScrollBar.cs
- BigInt.cs
- BasePattern.cs
- FilterQuery.cs
- FatalException.cs
- Guid.cs
- ResXResourceSet.cs
- BinaryWriter.cs
- LinqToSqlWrapper.cs
- SecuritySessionSecurityTokenProvider.cs
- HtmlHistory.cs
- AdRotator.cs
- DesignerHelpers.cs
- LayoutManager.cs
- securestring.cs
- ScrollItemPatternIdentifiers.cs
- PolicyManager.cs
- RepeatEnumerable.cs
- LinqDataSource.cs
- SmtpReplyReader.cs
- ResXResourceWriter.cs
- FormsAuthentication.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- TrustLevel.cs
- ColumnTypeConverter.cs
- TypeTypeConverter.cs
- CombinedGeometry.cs
- NavigationPropertyAccessor.cs
- EventListener.cs
- InterleavedZipPartStream.cs
- Debugger.cs
- DesignerActionGlyph.cs
- WindowsFormsHelpers.cs
- MobileControlPersister.cs
- DeflateStreamAsyncResult.cs
- SafeReadContext.cs
- XappLauncher.cs
- SymmetricAlgorithm.cs
- DataReaderContainer.cs
- WpfGeneratedKnownProperties.cs
- RootBrowserWindowAutomationPeer.cs
- SafeRegistryHandle.cs
- HtmlInputReset.cs
- OracleException.cs
- CodeDomSerializerException.cs
- Span.cs
- GeometryDrawing.cs
- PageParserFilter.cs
- TextBlock.cs
- TreeNodeMouseHoverEvent.cs
- DelegateArgument.cs
- WebPartsSection.cs
- COM2ICategorizePropertiesHandler.cs
- EncryptedData.cs
- PropertyNames.cs
- HyperLinkColumn.cs
- TypedReference.cs