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
- XpsColorContext.cs
- WebPartManagerInternals.cs
- Matrix.cs
- RepeaterCommandEventArgs.cs
- SpecularMaterial.cs
- TreeViewImageKeyConverter.cs
- ServiceObjectContainer.cs
- Baml2006ReaderContext.cs
- BindableTemplateBuilder.cs
- TableCell.cs
- RenderingEventArgs.cs
- IOThreadScheduler.cs
- PopupRootAutomationPeer.cs
- RequestUriProcessor.cs
- XsdCachingReader.cs
- KeyedHashAlgorithm.cs
- SystemTcpConnection.cs
- DesignRelationCollection.cs
- XpsFilter.cs
- FullTextLine.cs
- UnauthorizedWebPart.cs
- ObjectListField.cs
- ToolStripSettings.cs
- DataGridViewColumnStateChangedEventArgs.cs
- WindowsFormsEditorServiceHelper.cs
- DataGridViewRowHeaderCell.cs
- WebHttpBinding.cs
- TraceData.cs
- SimpleLine.cs
- SourceSwitch.cs
- Geometry3D.cs
- EmptyWorkItem.cs
- ConsumerConnectionPoint.cs
- BuildResultCache.cs
- WebPartTransformerAttribute.cs
- AutoResetEvent.cs
- SqlAliaser.cs
- DeclarativeCatalogPartDesigner.cs
- ExtractedStateEntry.cs
- NullableConverter.cs
- StorageAssociationTypeMapping.cs
- BasePattern.cs
- NavigationProperty.cs
- OutputWindow.cs
- ButtonBaseAutomationPeer.cs
- InstanceKeyCollisionException.cs
- validation.cs
- CategoryNameCollection.cs
- SystemWebCachingSectionGroup.cs
- TargetPerspective.cs
- ZipIOBlockManager.cs
- WebPartPersonalization.cs
- RuntimeHandles.cs
- COM2PropertyDescriptor.cs
- CopyAction.cs
- Char.cs
- HttpModulesSection.cs
- ReflectPropertyDescriptor.cs
- Listbox.cs
- GenericPrincipal.cs
- RelatedCurrencyManager.cs
- AuthenticationModuleElement.cs
- HttpCookiesSection.cs
- NotifyParentPropertyAttribute.cs
- XmlEncodedRawTextWriter.cs
- DataGridViewEditingControlShowingEventArgs.cs
- FixedMaxHeap.cs
- StoreItemCollection.cs
- DrawListViewColumnHeaderEventArgs.cs
- DataGridColumn.cs
- ToolTip.cs
- Recipient.cs
- ClrPerspective.cs
- Ipv6Element.cs
- MSAANativeProvider.cs
- PropertyChangingEventArgs.cs
- XmlSchemaExternal.cs
- WrappedIUnknown.cs
- ClientConvert.cs
- TemplateContentLoader.cs
- Localizer.cs
- Debug.cs
- TextBoxAutomationPeer.cs
- GroupPartitionExpr.cs
- processwaithandle.cs
- DataGridViewMethods.cs
- SqlGatherProducedAliases.cs
- DesignRelationCollection.cs
- Command.cs
- ReflectEventDescriptor.cs
- ProcessModelInfo.cs
- DataBoundLiteralControl.cs
- DesignTimeParseData.cs
- ParameterToken.cs
- FontFamilyValueSerializer.cs
- CellCreator.cs
- CornerRadius.cs
- PreviewPrintController.cs
- OleDbCommandBuilder.cs
- SqlDuplicator.cs