Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RemotingAttributes.cs
- FileSystemWatcher.cs
- TrackingMemoryStreamFactory.cs
- UnsafeNativeMethods.cs
- MenuItemStyle.cs
- BindMarkupExtensionSerializer.cs
- MatrixStack.cs
- Vector.cs
- EntityDataSourceStatementEditorForm.cs
- _FixedSizeReader.cs
- ImageBrush.cs
- ElementAction.cs
- HMACRIPEMD160.cs
- ByteStreamMessageEncoderFactory.cs
- ImageCodecInfoPrivate.cs
- IxmlLineInfo.cs
- DataTableNewRowEvent.cs
- XPathBuilder.cs
- StreamingContext.cs
- WebZone.cs
- TransformDescriptor.cs
- FilterQuery.cs
- InvalidCastException.cs
- TextEndOfLine.cs
- SafeCryptHandles.cs
- HttpException.cs
- IntSecurity.cs
- XPathArrayIterator.cs
- InstanceDescriptor.cs
- DocumentCollection.cs
- PolicyException.cs
- BrowserDefinition.cs
- WSTrust.cs
- GeneralTransform2DTo3D.cs
- SimpleHandlerFactory.cs
- ExceptionUtility.cs
- EntityCommandExecutionException.cs
- MediaTimeline.cs
- BrowserTree.cs
- SqlTopReducer.cs
- UrlMappingsModule.cs
- InlineUIContainer.cs
- OleDbReferenceCollection.cs
- BinaryCommonClasses.cs
- DataBoundLiteralControl.cs
- WebBrowser.cs
- RestHandlerFactory.cs
- TextServicesDisplayAttribute.cs
- TextTreeObjectNode.cs
- ExtenderControl.cs
- Wildcard.cs
- StructuredCompositeActivityDesigner.cs
- ChangeNode.cs
- XmlSchemaSimpleContentRestriction.cs
- XPathSingletonIterator.cs
- ToolStripDesignerAvailabilityAttribute.cs
- PathFigureCollectionValueSerializer.cs
- InProcStateClientManager.cs
- EngineSite.cs
- CellTreeNode.cs
- ToolStripRenderEventArgs.cs
- SmiRequestExecutor.cs
- RightsManagementEncryptionTransform.cs
- ContentPosition.cs
- OrderPreservingMergeHelper.cs
- FilterEventArgs.cs
- Form.cs
- DispatcherProcessingDisabled.cs
- BoolExpressionVisitors.cs
- EventRoute.cs
- HebrewCalendar.cs
- StateMachineWorkflowInstance.cs
- GridItemPattern.cs
- Permission.cs
- SmtpNtlmAuthenticationModule.cs
- TreeNodeMouseHoverEvent.cs
- Activation.cs
- MultiView.cs
- ClientTargetCollection.cs
- TogglePattern.cs
- TabItemAutomationPeer.cs
- ToolStripCollectionEditor.cs
- UiaCoreApi.cs
- unsafeIndexingFilterStream.cs
- SoapServerMessage.cs
- ColumnCollection.cs
- Point4D.cs
- ActivityExecutorSurrogate.cs
- EdmPropertyAttribute.cs
- WorkflowInstanceAbortedRecord.cs
- ILGenerator.cs
- ChannelBuilder.cs
- SoapSchemaImporter.cs
- PointKeyFrameCollection.cs
- BookmarkScope.cs
- XMLUtil.cs
- SessionChannels.cs
- EdmComplexTypeAttribute.cs
- XmlResolver.cs
- Composition.cs