Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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 sync 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; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLSingleStorage.cs
- ProtocolsConfigurationEntry.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- FormatConvertedBitmap.cs
- HttpConfigurationSystem.cs
- Ticks.cs
- PropertyEmitterBase.cs
- KeyValueSerializer.cs
- GridViewEditEventArgs.cs
- TextEditorLists.cs
- SrgsSemanticInterpretationTag.cs
- Line.cs
- CharacterMetrics.cs
- PeerPresenceInfo.cs
- SystemException.cs
- XPathBinder.cs
- DataGridRowHeader.cs
- CurrentChangedEventManager.cs
- BamlBinaryWriter.cs
- SystemPens.cs
- FlowPosition.cs
- ServerIdentity.cs
- XmlSerializerFactory.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- ListBindableAttribute.cs
- BinaryExpression.cs
- Int64Converter.cs
- TimelineCollection.cs
- RequestQueryParser.cs
- XappLauncher.cs
- CompilationUtil.cs
- DataContract.cs
- KnownTypesProvider.cs
- BuiltInExpr.cs
- PerformanceCounter.cs
- SQLInt16.cs
- FontSourceCollection.cs
- AppSettingsReader.cs
- DataServices.cs
- ValidatingReaderNodeData.cs
- InstancePersistenceException.cs
- CompatibleIComparer.cs
- AttributeParameterInfo.cs
- ConfigurationCollectionAttribute.cs
- HttpDigestClientElement.cs
- ServiceContractListItem.cs
- _UriTypeConverter.cs
- HttpProxyCredentialType.cs
- KeyValuePair.cs
- BrowsableAttribute.cs
- FigureHelper.cs
- CalendarAutoFormatDialog.cs
- Trace.cs
- CompositeCollectionView.cs
- EventMappingSettingsCollection.cs
- IsolatedStorageFileStream.cs
- NullableLongSumAggregationOperator.cs
- XmlSchemaType.cs
- VirtualPathData.cs
- ImageFormatConverter.cs
- RegexCompilationInfo.cs
- ValueQuery.cs
- ExceptionValidationRule.cs
- TypeReference.cs
- BasicAsyncResult.cs
- VerificationAttribute.cs
- NumericUpDownAcceleration.cs
- WindowsImpersonationContext.cs
- DependencyPropertyChangedEventArgs.cs
- HwndSource.cs
- ClientConvert.cs
- SqlDataSourceRefreshSchemaForm.cs
- StorageInfo.cs
- CDSsyncETWBCLProvider.cs
- QuaternionAnimationUsingKeyFrames.cs
- BufferBuilder.cs
- BlurBitmapEffect.cs
- PointAnimation.cs
- DesignRelationCollection.cs
- RelativeSource.cs
- ServicePointManager.cs
- Helper.cs
- XamlFilter.cs
- AutoGeneratedField.cs
- PrePrepareMethodAttribute.cs
- TemplateControlBuildProvider.cs
- Contracts.cs
- StandardBindingElement.cs
- HitTestResult.cs
- XmlQueryCardinality.cs
- StructuredProperty.cs
- PrePostDescendentsWalker.cs
- Function.cs
- PointF.cs
- Span.cs
- EventToken.cs
- TextFormatterImp.cs
- configsystem.cs
- SerializationTrace.cs
- PrintController.cs