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
- ColumnHeader.cs
- SqlCacheDependencyDatabase.cs
- AnnotationStore.cs
- DirectoryRootQuery.cs
- MaterialCollection.cs
- ServerProtocol.cs
- RefExpr.cs
- CallbackBehaviorAttribute.cs
- RSACryptoServiceProvider.cs
- WebPartMovingEventArgs.cs
- XmlArrayAttribute.cs
- SqlHelper.cs
- SqlServer2KCompatibilityCheck.cs
- Pkcs7Recipient.cs
- AsnEncodedData.cs
- UrlMappingsModule.cs
- DbBuffer.cs
- DynamicUpdateCommand.cs
- TemplateModeChangedEventArgs.cs
- StylusCaptureWithinProperty.cs
- SrgsGrammarCompiler.cs
- FreezableOperations.cs
- EdmSchemaAttribute.cs
- SettingsBase.cs
- ErrorTableItemStyle.cs
- GeometryHitTestResult.cs
- ItemsPresenter.cs
- QueryExtender.cs
- BitmapEffectInputConnector.cs
- BooleanConverter.cs
- AppDomain.cs
- ColorContextHelper.cs
- IPipelineRuntime.cs
- SafeProcessHandle.cs
- UnicodeEncoding.cs
- CoTaskMemSafeHandle.cs
- WindowsFormsLinkLabel.cs
- ToolStrip.cs
- FontSizeConverter.cs
- StringOutput.cs
- InheritablePropertyChangeInfo.cs
- Documentation.cs
- EdmValidator.cs
- ProxyHelper.cs
- SqlUDTStorage.cs
- Atom10FormatterFactory.cs
- NextPreviousPagerField.cs
- RoutedEventConverter.cs
- DateTimeSerializationSection.cs
- GraphicsPath.cs
- EventLogEntryCollection.cs
- BuildManagerHost.cs
- CompilerInfo.cs
- Msec.cs
- TextTreeTextNode.cs
- ProcessModule.cs
- CharAnimationUsingKeyFrames.cs
- TextFindEngine.cs
- EventSinkHelperWriter.cs
- CodeDelegateInvokeExpression.cs
- BitStream.cs
- GeneralTransform3D.cs
- TextSpan.cs
- StringPropertyBuilder.cs
- WarningException.cs
- OracleParameterBinding.cs
- ZipIOModeEnforcingStream.cs
- GAC.cs
- PasswordBox.cs
- ExtendedProperty.cs
- ReflectEventDescriptor.cs
- DbConnectionPoolGroupProviderInfo.cs
- WebBrowserUriTypeConverter.cs
- StateDesigner.TransitionInfo.cs
- BufferedWebEventProvider.cs
- PathStreamGeometryContext.cs
- RectIndependentAnimationStorage.cs
- ComboBox.cs
- VBIdentifierTrimConverter.cs
- ResumeStoryboard.cs
- ErrorLog.cs
- uribuilder.cs
- FilterEventArgs.cs
- DBConnectionString.cs
- parserscommon.cs
- DispatcherExceptionEventArgs.cs
- RunInstallerAttribute.cs
- HttpRuntime.cs
- ReferenceSchema.cs
- StructuredTypeEmitter.cs
- TabRenderer.cs
- GlyphElement.cs
- AnnotationStore.cs
- SetStoryboardSpeedRatio.cs
- Transform.cs
- Calendar.cs
- ResumeStoryboard.cs
- SqlTypeSystemProvider.cs
- AnnotationResourceChangedEventArgs.cs
- DataGridViewRowHeaderCell.cs