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
- ScopelessEnumAttribute.cs
- SelectionItemProviderWrapper.cs
- CannotUnloadAppDomainException.cs
- InvariantComparer.cs
- HandlerMappingMemo.cs
- SoapFault.cs
- WindowsRebar.cs
- ExpandCollapsePattern.cs
- ResourceDictionary.cs
- WSHttpTransportSecurityElement.cs
- EndEvent.cs
- VoiceSynthesis.cs
- UxThemeWrapper.cs
- VectorCollection.cs
- SmiGettersStream.cs
- SQLCharsStorage.cs
- Peer.cs
- HtmlInputFile.cs
- Stack.cs
- DrawingVisual.cs
- Win32.cs
- WSHttpBindingBaseElement.cs
- FormViewInsertedEventArgs.cs
- VersionConverter.cs
- DragDrop.cs
- TableLayoutStyle.cs
- TextSelectionProcessor.cs
- QfeChecker.cs
- RuleElement.cs
- PackageFilter.cs
- FileVersion.cs
- DbDataAdapter.cs
- RandomNumberGenerator.cs
- DashStyles.cs
- UserControl.cs
- DependentList.cs
- DataGridViewButtonColumn.cs
- BooleanConverter.cs
- PathSegment.cs
- CodeDomConfigurationHandler.cs
- UserControlCodeDomTreeGenerator.cs
- SoapConverter.cs
- TextHintingModeValidation.cs
- NamedPipeAppDomainProtocolHandler.cs
- Window.cs
- SafeHandle.cs
- CodeChecksumPragma.cs
- OwnerDrawPropertyBag.cs
- LockedAssemblyCache.cs
- PeerHelpers.cs
- UserControlDesigner.cs
- AssemblyEvidenceFactory.cs
- XmlnsCompatibleWithAttribute.cs
- SendKeys.cs
- DataControlCommands.cs
- UxThemeWrapper.cs
- DecimalKeyFrameCollection.cs
- SubMenuStyleCollectionEditor.cs
- UndoManager.cs
- ImportOptions.cs
- ServiceModelConfigurationSectionCollection.cs
- StylusButton.cs
- Object.cs
- WinCategoryAttribute.cs
- _Events.cs
- Currency.cs
- KeyValuePairs.cs
- CodeMethodReturnStatement.cs
- ChildChangedEventArgs.cs
- CapabilitiesSection.cs
- WindowPattern.cs
- ExpressionBuilderCollection.cs
- XmlNamespaceMapping.cs
- Parameter.cs
- RepeatButton.cs
- ObjectRef.cs
- ListControl.cs
- TreeSet.cs
- PropertyTabAttribute.cs
- DesignerDataColumn.cs
- EnumValidator.cs
- SchemaTypeEmitter.cs
- AssemblyAttributes.cs
- ConfigUtil.cs
- ReadOnlyAttribute.cs
- UnsafeMethods.cs
- ScrollProperties.cs
- WebPartRestoreVerb.cs
- MessageAction.cs
- DataGridViewRowsAddedEventArgs.cs
- HtmlTitle.cs
- RepeatInfo.cs
- DBParameter.cs
- DataObjectSettingDataEventArgs.cs
- X509SubjectKeyIdentifierClause.cs
- SqlWebEventProvider.cs
- ResourceDisplayNameAttribute.cs
- Icon.cs
- SoapIgnoreAttribute.cs
- HeaderCollection.cs