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
- ContentValidator.cs
- OdbcConnectionString.cs
- TraceProvider.cs
- ByteKeyFrameCollection.cs
- LogLogRecord.cs
- Table.cs
- AliasGenerator.cs
- ResolveNameEventArgs.cs
- DrawingGroup.cs
- InputBindingCollection.cs
- DataServiceClientException.cs
- WebPartsPersonalizationAuthorization.cs
- MouseEvent.cs
- SmiRequestExecutor.cs
- ScalarRestriction.cs
- PixelFormats.cs
- DataPagerField.cs
- IRCollection.cs
- SingleSelectRootGridEntry.cs
- CommentAction.cs
- DesignerSerializationOptionsAttribute.cs
- WebBrowserEvent.cs
- StorageModelBuildProvider.cs
- BitmapPalettes.cs
- XmlCompatibilityReader.cs
- PointKeyFrameCollection.cs
- LiteralControl.cs
- SQLStringStorage.cs
- Journaling.cs
- XmlTextEncoder.cs
- ScrollChangedEventArgs.cs
- NotSupportedException.cs
- DynamicDataRoute.cs
- TextChange.cs
- HitTestWithGeometryDrawingContextWalker.cs
- RootBrowserWindow.cs
- XamlParser.cs
- DataGridViewToolTip.cs
- ApplicationGesture.cs
- ServiceBehaviorAttribute.cs
- XmlnsDefinitionAttribute.cs
- TypedServiceOperationListItem.cs
- FontStyles.cs
- WebPartsPersonalizationAuthorization.cs
- Pair.cs
- ImageProxy.cs
- ProxyHwnd.cs
- ValueSerializer.cs
- StorageBasedPackageProperties.cs
- AttributeTableBuilder.cs
- DataPagerFieldCommandEventArgs.cs
- InvalidComObjectException.cs
- StreamUpdate.cs
- OfTypeExpression.cs
- ScaleTransform3D.cs
- CodeAttributeArgumentCollection.cs
- TextTreeNode.cs
- ConfigXmlAttribute.cs
- TextTreeInsertUndoUnit.cs
- LayoutTableCell.cs
- DataTableMapping.cs
- MethodBuilder.cs
- SecurityTokenProvider.cs
- DataGridColumnEventArgs.cs
- NodeCounter.cs
- BooleanStorage.cs
- CryptoKeySecurity.cs
- localization.cs
- Int16Animation.cs
- SpecularMaterial.cs
- XsltQilFactory.cs
- ToolStripDropDownClosingEventArgs.cs
- StateDesigner.TransitionInfo.cs
- SystemDiagnosticsSection.cs
- WebPartAddingEventArgs.cs
- CreatingCookieEventArgs.cs
- DataList.cs
- SingleConverter.cs
- DurableInstanceManager.cs
- FlowDocumentPaginator.cs
- BulletDecorator.cs
- CapabilitiesUse.cs
- Menu.cs
- IODescriptionAttribute.cs
- DeviceContexts.cs
- NativeWindow.cs
- entitydatasourceentitysetnameconverter.cs
- SqlDataSourceFilteringEventArgs.cs
- Trace.cs
- PropertyItem.cs
- CharEnumerator.cs
- TreeIterator.cs
- DependencyObject.cs
- Vector3DCollection.cs
- RestHandler.cs
- ClientScriptManager.cs
- EndEvent.cs
- PersonalizationStateInfoCollection.cs
- WorkflowInlining.cs
- FormView.cs