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
- TcpServerChannel.cs
- WebPartConnectionsEventArgs.cs
- DesignerLabelAdapter.cs
- HttpPostedFileWrapper.cs
- WindowsStreamSecurityBindingElement.cs
- DbProviderManifest.cs
- ProfileModule.cs
- SchemaImporter.cs
- Message.cs
- CommandBinding.cs
- Mouse.cs
- ListViewItemSelectionChangedEvent.cs
- DefinitionUpdate.cs
- AssertFilter.cs
- Matrix3DValueSerializer.cs
- StringFunctions.cs
- SourceFileBuildProvider.cs
- SqlConnectionPoolGroupProviderInfo.cs
- TimelineCollection.cs
- PreviousTrackingServiceAttribute.cs
- MergablePropertyAttribute.cs
- XhtmlBasicValidationSummaryAdapter.cs
- SerialPort.cs
- InvalidateEvent.cs
- QueryExpr.cs
- FormsIdentity.cs
- HttpWrapper.cs
- HelpFileFileNameEditor.cs
- PeerNearMe.cs
- DiscoveryReference.cs
- NodeLabelEditEvent.cs
- metadatamappinghashervisitor.cs
- UserControl.cs
- WindowsButton.cs
- StyleCollectionEditor.cs
- BitmapVisualManager.cs
- _IPv4Address.cs
- SqlCacheDependencyDatabase.cs
- NavigationCommands.cs
- BaseTypeViewSchema.cs
- SystemColors.cs
- CommandHelpers.cs
- SQLInt64Storage.cs
- StyleCollection.cs
- ProcessHostMapPath.cs
- Matrix3DConverter.cs
- QueueAccessMode.cs
- SimpleRecyclingCache.cs
- TemplateBindingExpression.cs
- SqlInternalConnection.cs
- ProfileModule.cs
- ObjectConverter.cs
- ImageBrush.cs
- ImageAttributes.cs
- DocumentGrid.cs
- TdsParameterSetter.cs
- BaseDataListComponentEditor.cs
- XmlSchemaType.cs
- SyndicationSerializer.cs
- ContainerParagraph.cs
- PrefixHandle.cs
- KnownTypes.cs
- RowVisual.cs
- ComponentEditorForm.cs
- Decoder.cs
- sqlnorm.cs
- XmlMemberMapping.cs
- User.cs
- SqlServices.cs
- ScaleTransform3D.cs
- PageStatePersister.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- CollectionViewGroup.cs
- PasswordDeriveBytes.cs
- ParseChildrenAsPropertiesAttribute.cs
- Stroke.cs
- DurableInstanceProvider.cs
- XmlUtil.cs
- TransformerInfoCollection.cs
- EnvelopeVersion.cs
- SkewTransform.cs
- IntegerCollectionEditor.cs
- X509AsymmetricSecurityKey.cs
- SchemaMapping.cs
- LocalizationComments.cs
- Root.cs
- StorageEndPropertyMapping.cs
- CheckableControlBaseAdapter.cs
- TypeCacheManager.cs
- MsmqHostedTransportConfiguration.cs
- CodeObject.cs
- SimpleBitVector32.cs
- XmlEventCache.cs
- Resources.Designer.cs
- DataGridRowDetailsEventArgs.cs
- DurableRuntimeValidator.cs
- ValidationSummary.cs
- MetaType.cs
- UniqueIdentifierService.cs
- FileSystemWatcher.cs