Code:
/ DotNET / DotNET / 8.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
- ConsumerConnectionPoint.cs
- CustomErrorsSection.cs
- AccessDataSourceView.cs
- BamlTreeMap.cs
- ItemMap.cs
- _OSSOCK.cs
- ThaiBuddhistCalendar.cs
- ContextItem.cs
- CompilerState.cs
- MachineSettingsSection.cs
- EFAssociationProvider.cs
- MobileUITypeEditor.cs
- EndpointDiscoveryMetadata11.cs
- AlternationConverter.cs
- UrlMappingCollection.cs
- IntegerValidatorAttribute.cs
- URLMembershipCondition.cs
- MessageQueue.cs
- Win32Native.cs
- SByteConverter.cs
- XPathNodeHelper.cs
- AsyncCallback.cs
- UxThemeWrapper.cs
- EventRoute.cs
- TextRunTypographyProperties.cs
- ThicknessAnimationUsingKeyFrames.cs
- OleDbDataReader.cs
- TextProperties.cs
- ExpandCollapseProviderWrapper.cs
- JournalEntryListConverter.cs
- ProfileParameter.cs
- CommunicationObjectFaultedException.cs
- SqlUserDefinedTypeAttribute.cs
- XmlIlTypeHelper.cs
- SqlDataSourceCache.cs
- ConstructorExpr.cs
- FunctionGenerator.cs
- SqlServices.cs
- MatrixAnimationUsingPath.cs
- OperatorExpressions.cs
- ConfigurationSectionGroup.cs
- SplitContainer.cs
- DataGridViewCellValidatingEventArgs.cs
- XamlSerializer.cs
- PrimitiveCodeDomSerializer.cs
- Axis.cs
- DoubleLink.cs
- Lasso.cs
- PeerPresenceInfo.cs
- ConstructorNeedsTagAttribute.cs
- activationcontext.cs
- OSFeature.cs
- SqlCacheDependencyDatabase.cs
- Propagator.Evaluator.cs
- IpcChannelHelper.cs
- ConnectionManagementElement.cs
- OracleConnectionString.cs
- RequestCachingSection.cs
- DecoderFallbackWithFailureFlag.cs
- CharacterHit.cs
- HwndKeyboardInputProvider.cs
- DBSqlParserColumn.cs
- CopyCodeAction.cs
- TextFormatterHost.cs
- LeaseManager.cs
- COM2IManagedPerPropertyBrowsingHandler.cs
- MetadataCollection.cs
- Filter.cs
- XamlTemplateSerializer.cs
- DefaultWorkflowTransactionService.cs
- BitmapSizeOptions.cs
- InfiniteIntConverter.cs
- ProxySimple.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- DataGridSortCommandEventArgs.cs
- Range.cs
- TextUtf8RawTextWriter.cs
- MimeMapping.cs
- BitmapImage.cs
- CopyOnWriteList.cs
- WindowExtensionMethods.cs
- DiscoveryDocumentReference.cs
- WebServiceReceiveDesigner.cs
- ButtonColumn.cs
- RuntimeConfig.cs
- FolderLevelBuildProviderCollection.cs
- ServiceBehaviorAttribute.cs
- Vector3DAnimationBase.cs
- TransformGroup.cs
- Thread.cs
- UserInitiatedNavigationPermission.cs
- Adorner.cs
- GridErrorDlg.cs
- _AutoWebProxyScriptWrapper.cs
- ElementHost.cs
- KnownBoxes.cs
- DataTableTypeConverter.cs
- Base64Stream.cs
- TextMetrics.cs
- HotSpotCollection.cs