Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- ValueTypeFixupInfo.cs
- AttributeQuery.cs
- DataGridViewCellParsingEventArgs.cs
- DiscoveryClientDuplexChannel.cs
- TextBox.cs
- CellTreeSimplifier.cs
- TableLayoutStyle.cs
- MaxSessionCountExceededException.cs
- FormViewCommandEventArgs.cs
- UpdatePanelControlTrigger.cs
- BorderGapMaskConverter.cs
- ArithmeticLiteral.cs
- DataGridViewCellStyleChangedEventArgs.cs
- RC2.cs
- CapabilitiesSection.cs
- CannotUnloadAppDomainException.cs
- HierarchicalDataSourceConverter.cs
- FastEncoder.cs
- MetadataExchangeBindings.cs
- OutputBuffer.cs
- GridProviderWrapper.cs
- OdbcConnection.cs
- TextTreePropertyUndoUnit.cs
- InstancePersistenceContext.cs
- WindowsFormsHost.cs
- ExpressionBuilder.cs
- Win32SafeHandles.cs
- OleDbPropertySetGuid.cs
- ConfigurationManagerHelperFactory.cs
- RowSpanVector.cs
- ValueProviderWrapper.cs
- CqlQuery.cs
- TableLayoutPanel.cs
- DataListCommandEventArgs.cs
- BinHexEncoding.cs
- TdsParserSessionPool.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- NavigationCommands.cs
- DataGridPagerStyle.cs
- Simplifier.cs
- ProcessRequestArgs.cs
- PLINQETWProvider.cs
- ChooseAction.cs
- SQLChars.cs
- ViewPort3D.cs
- HttpCacheVaryByContentEncodings.cs
- COAUTHINFO.cs
- IsolatedStorageFileStream.cs
- StateElement.cs
- ToolStripControlHost.cs
- Parameter.cs
- FontSourceCollection.cs
- DiagnosticSection.cs
- DocumentGridContextMenu.cs
- ParameterCollection.cs
- SoapFaultCodes.cs
- Guid.cs
- HandleRef.cs
- GestureRecognizer.cs
- ChannelRequirements.cs
- ImmutableCollection.cs
- SqlIdentifier.cs
- SelectionPatternIdentifiers.cs
- OleDbConnection.cs
- DataGridViewColumn.cs
- WindowsEditBoxRange.cs
- ResolveNameEventArgs.cs
- InitializationEventAttribute.cs
- ExtensionElementCollection.cs
- SafeWaitHandle.cs
- TypeGeneratedEventArgs.cs
- Encoding.cs
- DocumentSchemaValidator.cs
- ListViewPagedDataSource.cs
- FilteredDataSetHelper.cs
- FileIOPermission.cs
- Int64KeyFrameCollection.cs
- BinarySerializer.cs
- FixedPage.cs
- XmlTextReaderImpl.cs
- CompositionTarget.cs
- RenderTargetBitmap.cs
- DbDeleteCommandTree.cs
- CodeEventReferenceExpression.cs
- ProfilePropertySettingsCollection.cs
- SmtpMail.cs
- ResourcesBuildProvider.cs
- HtmlShimManager.cs
- WaitHandleCannotBeOpenedException.cs
- BamlLocalizableResource.cs
- TextServicesManager.cs
- DebugView.cs
- MappedMetaModel.cs
- PersonalizationProvider.cs
- Unit.cs
- ApplicationTrust.cs
- ControlCachePolicy.cs
- SiteOfOriginContainer.cs
- AdapterDictionary.cs
- RequestQueue.cs