Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- EmbeddedMailObjectsCollection.cs
- TextPointer.cs
- HealthMonitoringSectionHelper.cs
- TypeElement.cs
- _LazyAsyncResult.cs
- XmlNodeList.cs
- VirtualPath.cs
- XpsS0ValidatingLoader.cs
- OutputCacheSettings.cs
- EarlyBoundInfo.cs
- HttpTransportSecurity.cs
- ModelMemberCollection.cs
- DeferredTextReference.cs
- SoapAttributeOverrides.cs
- DiscardableAttribute.cs
- ContextBase.cs
- PagerSettings.cs
- DataMisalignedException.cs
- ButtonField.cs
- OpCopier.cs
- WebPartConnectionsCancelEventArgs.cs
- ConsoleTraceListener.cs
- Native.cs
- ScriptReferenceEventArgs.cs
- CustomValidator.cs
- ObjectDataSource.cs
- LockedAssemblyCache.cs
- Image.cs
- SamlAuthorizationDecisionStatement.cs
- ZipIOLocalFileHeader.cs
- CodeNamespaceCollection.cs
- DataGridCaption.cs
- OleDbConnection.cs
- RoutedUICommand.cs
- ZipIOExtraFieldElement.cs
- WinFormsSpinner.cs
- SerializationFieldInfo.cs
- RequestTimeoutManager.cs
- X509ClientCertificateAuthentication.cs
- ContactManager.cs
- XmlSchemaComplexContent.cs
- LinqToSqlWrapper.cs
- InheritanceContextHelper.cs
- MetadataPropertyCollection.cs
- HttpGetProtocolImporter.cs
- PropertyValueChangedEvent.cs
- ModelTreeEnumerator.cs
- documentsequencetextpointer.cs
- BasicExpandProvider.cs
- PropertyGrid.cs
- DockPattern.cs
- UpdateProgress.cs
- BoundField.cs
- SpecialNameAttribute.cs
- Encoder.cs
- AccessDataSourceView.cs
- LoginName.cs
- CreateDataSourceDialog.cs
- CDSCollectionETWBCLProvider.cs
- TextContainerChangeEventArgs.cs
- RawStylusInput.cs
- UntrustedRecipientException.cs
- DetailsViewPagerRow.cs
- LineBreak.cs
- HtmlTextArea.cs
- ColumnHeader.cs
- Tag.cs
- TableStyle.cs
- Converter.cs
- NumericUpDown.cs
- ISFTagAndGuidCache.cs
- MappingMetadataHelper.cs
- SingleKeyFrameCollection.cs
- ItemList.cs
- Int16KeyFrameCollection.cs
- FontUnit.cs
- JournalEntryStack.cs
- WebHeaderCollection.cs
- Add.cs
- PropertyGridView.cs
- Merger.cs
- ToolStripPanelSelectionGlyph.cs
- AttributeInfo.cs
- ResourcePart.cs
- CatalogPartDesigner.cs
- BamlReader.cs
- XsdDuration.cs
- Assert.cs
- QueryConverter.cs
- ServiceMemoryGates.cs
- ParameterToken.cs
- xdrvalidator.cs
- MulticastNotSupportedException.cs
- ChtmlTextBoxAdapter.cs
- _AutoWebProxyScriptEngine.cs
- RelatedCurrencyManager.cs
- SignedInfo.cs
- Line.cs
- ClientBase.cs
- ZipPackage.cs