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
- UnaryExpression.cs
- MetaChildrenColumn.cs
- MediaContextNotificationWindow.cs
- SchemaElementLookUpTableEnumerator.cs
- WebPartHeaderCloseVerb.cs
- EndpointBehaviorElementCollection.cs
- ConfigurationStrings.cs
- WebPartMenu.cs
- TextProviderWrapper.cs
- MouseButton.cs
- ContractMethodInfo.cs
- Rect.cs
- OptimizedTemplateContentHelper.cs
- CircleEase.cs
- AuthenticationConfig.cs
- ProxyBuilder.cs
- ProfileProvider.cs
- shaper.cs
- QualifierSet.cs
- RangeValuePattern.cs
- DataGridLength.cs
- COM2Properties.cs
- SQLDoubleStorage.cs
- ClientRuntimeConfig.cs
- SizeConverter.cs
- OdbcConnectionStringbuilder.cs
- PrefixHandle.cs
- ObjectParameterCollection.cs
- RequestStatusBarUpdateEventArgs.cs
- DayRenderEvent.cs
- SafeNativeMethods.cs
- PlatformCulture.cs
- HierarchicalDataBoundControl.cs
- ColumnReorderedEventArgs.cs
- ImportDesigner.xaml.cs
- NativeWrapper.cs
- SingleResultAttribute.cs
- SecurityNegotiationException.cs
- StringSorter.cs
- XmlSchemaComplexContentExtension.cs
- QilInvokeEarlyBound.cs
- ScrollEvent.cs
- WmlControlAdapter.cs
- SafeMemoryMappedFileHandle.cs
- CommandDevice.cs
- CodeCatchClauseCollection.cs
- EditingScope.cs
- MetadataSource.cs
- _TransmitFileOverlappedAsyncResult.cs
- AppSettingsReader.cs
- ManagementClass.cs
- VectorAnimation.cs
- ScriptServiceAttribute.cs
- TransformDescriptor.cs
- ImpersonateTokenRef.cs
- SolidColorBrush.cs
- ConditionCollection.cs
- ValidationUtility.cs
- TimeSpanValidator.cs
- ApplicationId.cs
- FileRegion.cs
- CacheRequest.cs
- WithStatement.cs
- RefExpr.cs
- WebPartZoneCollection.cs
- WebBrowserSiteBase.cs
- WsdlInspector.cs
- DbConnectionPoolGroupProviderInfo.cs
- XmlComplianceUtil.cs
- SplayTreeNode.cs
- baseaxisquery.cs
- FontUnit.cs
- DelegatedStream.cs
- DBDataPermission.cs
- XmlDataSource.cs
- ServiceReference.cs
- PopupEventArgs.cs
- JsonReader.cs
- FloatMinMaxAggregationOperator.cs
- NamedPipeHostedTransportConfiguration.cs
- ValidationErrorEventArgs.cs
- Annotation.cs
- HebrewCalendar.cs
- TextHidden.cs
- FontSourceCollection.cs
- XmlNodeList.cs
- MetafileHeader.cs
- StylusLogic.cs
- XmlILAnnotation.cs
- ThicknessKeyFrameCollection.cs
- ContentType.cs
- ProfileSettings.cs
- WebEventCodes.cs
- AttributeData.cs
- DataGridViewCellStyle.cs
- ListSurrogate.cs
- CommandBinding.cs
- DrawingContext.cs
- ComplexObject.cs
- ReadOnlyDictionary.cs