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
- CodeMemberEvent.cs
- SkinBuilder.cs
- PrimitiveXmlSerializers.cs
- RegexStringValidator.cs
- IdentityNotMappedException.cs
- SendingRequestEventArgs.cs
- CallContext.cs
- SafeHandles.cs
- XmlReflectionMember.cs
- WebPartTransformer.cs
- DataGridViewToolTip.cs
- WinFormsSpinner.cs
- EntityDataSourceValidationException.cs
- WebPartCloseVerb.cs
- SessionStateItemCollection.cs
- BindableTemplateBuilder.cs
- StringReader.cs
- ExtendedProperty.cs
- ContextProperty.cs
- ReadOnlyObservableCollection.cs
- UnlockCardRequest.cs
- activationcontext.cs
- WebPartMinimizeVerb.cs
- DataSourceXmlTextReader.cs
- TextSelectionHighlightLayer.cs
- ServiceHostFactory.cs
- TypeElement.cs
- IApplicationTrustManager.cs
- RegexInterpreter.cs
- Cursors.cs
- DecryptedHeader.cs
- TraversalRequest.cs
- RadioButtonFlatAdapter.cs
- TimeSpanConverter.cs
- XmlCharacterData.cs
- CreateWorkflowOwnerCommand.cs
- UniqueEventHelper.cs
- DbProviderConfigurationHandler.cs
- TableRowGroup.cs
- TargetConverter.cs
- StrokeNode.cs
- RotationValidation.cs
- AttributeEmitter.cs
- Collection.cs
- Dispatcher.cs
- SchemaAttDef.cs
- EntityViewGenerationConstants.cs
- WebPartActionVerb.cs
- ListDesigner.cs
- UrlMappingsModule.cs
- DocumentViewer.cs
- XmlSerializationReader.cs
- WebEventTraceProvider.cs
- LinkUtilities.cs
- ViewManager.cs
- SqlSelectStatement.cs
- PropertyValueUIItem.cs
- PersonalizationState.cs
- DmlSqlGenerator.cs
- Listbox.cs
- TargetParameterCountException.cs
- Part.cs
- ValidatingReaderNodeData.cs
- Int16AnimationBase.cs
- DataGridViewButtonColumn.cs
- TemplatedControlDesigner.cs
- ResourcePermissionBaseEntry.cs
- TypeUsage.cs
- PropertyMetadata.cs
- CachedPathData.cs
- InputManager.cs
- SchemaCollectionCompiler.cs
- ProviderUtil.cs
- PopupControlService.cs
- XmlMapping.cs
- SrgsText.cs
- BlockUIContainer.cs
- PrivilegeNotHeldException.cs
- EmptyEnumerator.cs
- CollectionBase.cs
- SolidBrush.cs
- DataSourceControl.cs
- TransformationRules.cs
- LinkArea.cs
- Panel.cs
- DependencyPropertyKind.cs
- ObjectDataSourceMethodEditor.cs
- BaseConfigurationRecord.cs
- DataTrigger.cs
- IListConverters.cs
- EventProviderTraceListener.cs
- EditorZone.cs
- WebPartDescriptionCollection.cs
- DoubleCollectionConverter.cs
- MethodCallTranslator.cs
- ProfilePropertyMetadata.cs
- ContractBase.cs
- TableMethodGenerator.cs
- ExtensionQuery.cs
- NonVisualControlAttribute.cs