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
- EventLogTraceListener.cs
- MethodMessage.cs
- SqlTypesSchemaImporter.cs
- DatatypeImplementation.cs
- CachingHintValidation.cs
- DocumentPageHost.cs
- CompensateDesigner.cs
- ValueUnavailableException.cs
- DataGridViewLinkCell.cs
- DataGridCaption.cs
- SelectionGlyph.cs
- CheckBoxBaseAdapter.cs
- SoapAttributeOverrides.cs
- CodeIdentifier.cs
- DrawListViewSubItemEventArgs.cs
- EventLogLink.cs
- Helper.cs
- TTSEvent.cs
- DbgUtil.cs
- OrderedDictionary.cs
- FixedFindEngine.cs
- ColorPalette.cs
- BitmapEffectState.cs
- PageParserFilter.cs
- FileStream.cs
- State.cs
- MulticastNotSupportedException.cs
- TypedTableBaseExtensions.cs
- FormViewInsertedEventArgs.cs
- RijndaelManagedTransform.cs
- WebSysDisplayNameAttribute.cs
- SqlTrackingWorkflowInstance.cs
- VisualState.cs
- ITreeGenerator.cs
- SignedPkcs7.cs
- TcpTransportSecurity.cs
- OledbConnectionStringbuilder.cs
- DateTimePicker.cs
- BaseCodeDomTreeGenerator.cs
- HttpClientCertificate.cs
- processwaithandle.cs
- ColorTransformHelper.cs
- SHA384Managed.cs
- FlowLayoutPanel.cs
- ControlUtil.cs
- BindableAttribute.cs
- COM2PropertyDescriptor.cs
- EntityContainerEmitter.cs
- SID.cs
- ReflectionHelper.cs
- HtmlInputSubmit.cs
- MyContact.cs
- ListViewContainer.cs
- CqlParserHelpers.cs
- AmbientLight.cs
- StateMachineAction.cs
- ListDictionaryInternal.cs
- QilExpression.cs
- ListViewItemMouseHoverEvent.cs
- RemoteWebConfigurationHostStream.cs
- TextServicesCompartment.cs
- MarkupCompiler.cs
- NavigatingCancelEventArgs.cs
- BulletChrome.cs
- HttpStaticObjectsCollectionWrapper.cs
- Visual.cs
- CustomActivityDesigner.cs
- XmlNodeChangedEventArgs.cs
- WebPartRestoreVerb.cs
- rsa.cs
- COM2TypeInfoProcessor.cs
- CssClassPropertyAttribute.cs
- MultiBinding.cs
- ContentHostHelper.cs
- CompilerResults.cs
- XamlToRtfParser.cs
- DatagridviewDisplayedBandsData.cs
- WebErrorHandler.cs
- SafeFileHandle.cs
- QueryCacheKey.cs
- Utilities.cs
- GridLength.cs
- GZipStream.cs
- Int16Animation.cs
- QilExpression.cs
- RegisteredDisposeScript.cs
- InheritanceContextChangedEventManager.cs
- IdentifierService.cs
- TabItemWrapperAutomationPeer.cs
- ReflectionHelper.cs
- VisualStyleInformation.cs
- FormViewInsertEventArgs.cs
- InternalControlCollection.cs
- BulletChrome.cs
- FileLoadException.cs
- NumericUpDownAcceleration.cs
- TimeZone.cs
- Divide.cs
- AuthenticationConfig.cs
- TdsParser.cs