Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EvidenceTypeDescriptor.cs
- X509ChainElement.cs
- MediaScriptCommandRoutedEventArgs.cs
- ErrorWebPart.cs
- ImageCodecInfo.cs
- MediaContext.cs
- AtomServiceDocumentSerializer.cs
- TableAdapterManagerGenerator.cs
- ToolStripLabel.cs
- DataListItemCollection.cs
- CodeTypeParameter.cs
- DbConnectionPoolCounters.cs
- EntityDataSourceUtil.cs
- MessageEventSubscriptionService.cs
- KeyNotFoundException.cs
- FusionWrap.cs
- HtmlPhoneCallAdapter.cs
- FilterException.cs
- DataPagerCommandEventArgs.cs
- DataContractJsonSerializer.cs
- ListBindingConverter.cs
- Ray3DHitTestResult.cs
- DataListDesigner.cs
- Random.cs
- ZipIOLocalFileBlock.cs
- SmiEventSink_Default.cs
- ComponentResourceKey.cs
- CommonRemoteMemoryBlock.cs
- GlyphManager.cs
- SqlRowUpdatedEvent.cs
- XmlNodeChangedEventManager.cs
- XmlnsPrefixAttribute.cs
- PointAnimationUsingPath.cs
- Utils.cs
- RemoteTokenFactory.cs
- CreateUserWizard.cs
- SystemIPv4InterfaceProperties.cs
- AutoResetEvent.cs
- StsCommunicationException.cs
- ListViewTableCell.cs
- MonthChangedEventArgs.cs
- ClientFormsAuthenticationCredentials.cs
- LabelDesigner.cs
- SiteMapSection.cs
- CodeDirectionExpression.cs
- StateBag.cs
- Timer.cs
- Point3DAnimationUsingKeyFrames.cs
- CodeChecksumPragma.cs
- ComponentRenameEvent.cs
- Shared.cs
- DataBindingHandlerAttribute.cs
- DrawingContextWalker.cs
- UnwrappedTypesXmlSerializerManager.cs
- XmlEntity.cs
- PlanCompiler.cs
- util.cs
- IgnoreFlushAndCloseStream.cs
- XmlIlGenerator.cs
- controlskin.cs
- SessionStateUtil.cs
- WebPartConnectionsCancelEventArgs.cs
- RequestStatusBarUpdateEventArgs.cs
- EmptyStringExpandableObjectConverter.cs
- _DynamicWinsockMethods.cs
- ParameterModifier.cs
- EndEvent.cs
- _AcceptOverlappedAsyncResult.cs
- SamlAssertion.cs
- StorageConditionPropertyMapping.cs
- ProfileService.cs
- CapabilitiesUse.cs
- XPathEmptyIterator.cs
- Msec.cs
- RTLAwareMessageBox.cs
- ExtendedPropertyDescriptor.cs
- DataPagerFieldCommandEventArgs.cs
- MultiDataTrigger.cs
- CachedBitmap.cs
- ContextStaticAttribute.cs
- DocumentViewerBase.cs
- FlowPosition.cs
- COMException.cs
- StylusEventArgs.cs
- GenerateScriptTypeAttribute.cs
- ActivityStateRecord.cs
- StateWorkerRequest.cs
- Int32Animation.cs
- LicFileLicenseProvider.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- TreeNodeBindingCollection.cs
- Graph.cs
- SystemResources.cs
- HitTestWithGeometryDrawingContextWalker.cs
- RawKeyboardInputReport.cs
- Membership.cs
- EFTableProvider.cs
- UrlAuthFailedErrorFormatter.cs
- RSAOAEPKeyExchangeDeformatter.cs
- Int32Rect.cs