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
- Stream.cs
- HotSpotCollection.cs
- DbUpdateCommandTree.cs
- TlsnegoTokenAuthenticator.cs
- WindowsListViewItemCheckBox.cs
- MobileRedirect.cs
- JavaScriptSerializer.cs
- DataSourceViewSchemaConverter.cs
- CheckPair.cs
- ProtocolsConfigurationHandler.cs
- FunctionNode.cs
- RichTextBox.cs
- HandlerFactoryWrapper.cs
- ArgumentValidation.cs
- ConnectionPoint.cs
- ClientSideQueueItem.cs
- RuntimeIdentifierPropertyAttribute.cs
- BrowserDefinition.cs
- XmlSerializerAssemblyAttribute.cs
- ConfigurationManagerHelperFactory.cs
- XmlnsPrefixAttribute.cs
- Journal.cs
- DiffuseMaterial.cs
- SymbolTable.cs
- FontStyleConverter.cs
- TheQuery.cs
- DependentTransaction.cs
- IndentedTextWriter.cs
- MessageBox.cs
- EventHandlerList.cs
- AuthenticationService.cs
- EllipseGeometry.cs
- XmlArrayItemAttributes.cs
- ProvidePropertyAttribute.cs
- PlainXmlDeserializer.cs
- Helpers.cs
- SolidBrush.cs
- OptimizedTemplateContentHelper.cs
- GlobalEventManager.cs
- BamlResourceSerializer.cs
- EpmTargetTree.cs
- FixedSOMTableCell.cs
- SubMenuStyleCollection.cs
- ListChangedEventArgs.cs
- SafeEventLogReadHandle.cs
- RequestQueue.cs
- AutomationPatternInfo.cs
- ContainerUIElement3D.cs
- MailHeaderInfo.cs
- ResXResourceSet.cs
- CrossAppDomainChannel.cs
- ThemeDictionaryExtension.cs
- MsmqChannelFactoryBase.cs
- XmlILStorageConverter.cs
- OleDbPermission.cs
- ImmComposition.cs
- MimeTypeAttribute.cs
- DataKeyArray.cs
- COAUTHINFO.cs
- AsmxEndpointPickerExtension.cs
- PreservationFileWriter.cs
- SrgsRule.cs
- WmlCommandAdapter.cs
- EventMappingSettings.cs
- TextFormatterContext.cs
- ErrorFormatterPage.cs
- ADMembershipProvider.cs
- SamlNameIdentifierClaimResource.cs
- IntegerFacetDescriptionElement.cs
- CodeObjectCreateExpression.cs
- StringCollectionEditor.cs
- Point4DConverter.cs
- ConfigurationSettings.cs
- Renderer.cs
- SystemIPGlobalStatistics.cs
- TimeSpanOrInfiniteConverter.cs
- CodeNamespaceImportCollection.cs
- WindowsSolidBrush.cs
- PassportAuthentication.cs
- TextEmbeddedObject.cs
- IntellisenseTextBox.designer.cs
- MediaEntryAttribute.cs
- InputGestureCollection.cs
- IpcChannelHelper.cs
- EdmProperty.cs
- ImmutableObjectAttribute.cs
- GenericsInstances.cs
- Unit.cs
- HttpContext.cs
- ModuleConfigurationInfo.cs
- DefaultTextStoreTextComposition.cs
- WebPartsPersonalization.cs
- StreamingContext.cs
- SecurityVerifiedMessage.cs
- VisualTreeFlattener.cs
- NativeMethods.cs
- isolationinterop.cs
- TypedTableBaseExtensions.cs
- RectAnimationClockResource.cs
- WinInetCache.cs