Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / AsyncOperation.cs / 1305376 / 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 [....] 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; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// 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 [....] 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; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HybridWebProxyFinder.cs
- Int64Animation.cs
- HostedElements.cs
- CompiledRegexRunner.cs
- MaskedTextBox.cs
- XmlObjectSerializerWriteContextComplex.cs
- PixelShader.cs
- SecurityVersion.cs
- DescendantBaseQuery.cs
- MultiDataTrigger.cs
- SourceInterpreter.cs
- ButtonColumn.cs
- Application.cs
- CookieHandler.cs
- RangeValidator.cs
- SqlNotificationEventArgs.cs
- GB18030Encoding.cs
- BuildProviderCollection.cs
- CustomErrorsSection.cs
- QilTargetType.cs
- ArgumentsParser.cs
- ContextStack.cs
- UInt64Storage.cs
- ReservationNotFoundException.cs
- AppSettingsExpressionBuilder.cs
- SqlEnums.cs
- MemberPathMap.cs
- SymbolEqualComparer.cs
- UrlPath.cs
- SimpleTextLine.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- SchemaHelper.cs
- TableParagraph.cs
- CheckPair.cs
- HealthMonitoringSectionHelper.cs
- XmlSecureResolver.cs
- ReadOnlyHierarchicalDataSourceView.cs
- StoreUtilities.cs
- BitmapEffectGeneralTransform.cs
- StylusOverProperty.cs
- SecurityMessageProperty.cs
- TextElement.cs
- mactripleDES.cs
- RoleServiceManager.cs
- AppDomain.cs
- Exceptions.cs
- FeatureSupport.cs
- CallbackValidatorAttribute.cs
- MatchAttribute.cs
- RectAnimationUsingKeyFrames.cs
- FixedDocumentPaginator.cs
- DocumentOutline.cs
- QueryModel.cs
- TextDecorationUnitValidation.cs
- GeometryGroup.cs
- ping.cs
- VectorConverter.cs
- EventProxy.cs
- NumberFunctions.cs
- compensatingcollection.cs
- RoutedEventConverter.cs
- PlainXmlSerializer.cs
- ReaderWriterLock.cs
- TableRow.cs
- SecurityElement.cs
- RequestCacheValidator.cs
- EventLogQuery.cs
- CollectionBase.cs
- CounterSetInstance.cs
- Resources.Designer.cs
- ImageButton.cs
- Shape.cs
- _ConnectStream.cs
- ExpandableObjectConverter.cs
- SubclassTypeValidator.cs
- CombinedGeometry.cs
- PrintPreviewControl.cs
- ResourceCategoryAttribute.cs
- BindingList.cs
- DependencyPropertyDescriptor.cs
- DataAdapter.cs
- Automation.cs
- DropTarget.cs
- XamlTreeBuilderBamlRecordWriter.cs
- FocusChangedEventArgs.cs
- Accessible.cs
- StandardBindingReliableSessionElement.cs
- GatewayDefinition.cs
- XmlIlTypeHelper.cs
- XmlNamedNodeMap.cs
- PropertyExpression.cs
- ToolStripSplitButton.cs
- CodeRemoveEventStatement.cs
- TemplateControlBuildProvider.cs
- BitmapFrame.cs
- MetadataCacheItem.cs
- WmlSelectionListAdapter.cs
- IConvertible.cs
- LambdaExpression.cs
- TextFormatterImp.cs