Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- GroupBoxAutomationPeer.cs
- DrawingCollection.cs
- FederatedMessageSecurityOverHttpElement.cs
- DataTableNewRowEvent.cs
- BufferedGraphicsManager.cs
- GenericRootAutomationPeer.cs
- TaskForm.cs
- errorpatternmatcher.cs
- Binding.cs
- VideoDrawing.cs
- MasterPageBuildProvider.cs
- BasicExpressionVisitor.cs
- LabelDesigner.cs
- HttpProfileBase.cs
- XsltOutput.cs
- ManifestSignatureInformation.cs
- Matrix3D.cs
- TypeGeneratedEventArgs.cs
- ControllableStoryboardAction.cs
- _RequestCacheProtocol.cs
- MeasureData.cs
- XmlEntity.cs
- DataGridPageChangedEventArgs.cs
- DataGridViewDataConnection.cs
- PeerCollaboration.cs
- OrderByBuilder.cs
- TypeInitializationException.cs
- PeerCollaborationPermission.cs
- SettingsAttributes.cs
- BooleanFunctions.cs
- BlockExpression.cs
- ChineseLunisolarCalendar.cs
- SchemaConstraints.cs
- _ConnectOverlappedAsyncResult.cs
- TextServicesHost.cs
- WorkItem.cs
- SQLByte.cs
- DispatcherFrame.cs
- TableParagraph.cs
- ListMarkerSourceInfo.cs
- DbProviderFactoriesConfigurationHandler.cs
- Error.cs
- PolicyLevel.cs
- FrameworkContextData.cs
- UIHelper.cs
- BitVector32.cs
- MetadataArtifactLoaderCompositeResource.cs
- WebPartConnection.cs
- ClientScriptManager.cs
- RtfToken.cs
- JoinElimination.cs
- NCryptNative.cs
- BitmapEffectCollection.cs
- CallId.cs
- StrongNameMembershipCondition.cs
- ObjectHelper.cs
- SpotLight.cs
- StateMachineHelpers.cs
- FixedSOMTableRow.cs
- Rect3DValueSerializer.cs
- EpmSyndicationContentSerializer.cs
- OdbcEnvironment.cs
- TableLayoutRowStyleCollection.cs
- ChildTable.cs
- ColorMap.cs
- NodeFunctions.cs
- BinaryCommonClasses.cs
- TempFiles.cs
- XmlIgnoreAttribute.cs
- DefaultProxySection.cs
- DummyDataSource.cs
- TcpConnectionPool.cs
- CapabilitiesSection.cs
- XslTransform.cs
- PostBackTrigger.cs
- SmiMetaData.cs
- FeatureAttribute.cs
- Function.cs
- WindowsToolbar.cs
- IsolatedStoragePermission.cs
- InternalUserCancelledException.cs
- Group.cs
- SystemEvents.cs
- BeginStoryboard.cs
- SoapProtocolReflector.cs
- TrustSection.cs
- FileCodeGroup.cs
- UIHelper.cs
- ConstraintConverter.cs
- NonVisualControlAttribute.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- SspiHelper.cs
- Visitor.cs
- WeakReadOnlyCollection.cs
- XPathArrayIterator.cs
- WebPartAddingEventArgs.cs
- MatrixTransform3D.cs
- ScriptIgnoreAttribute.cs
- MappingModelBuildProvider.cs
- DataGridView.cs