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
- ItemCollection.cs
- DataControlCommands.cs
- SparseMemoryStream.cs
- BamlTreeUpdater.cs
- COM2IDispatchConverter.cs
- HtmlControl.cs
- OleDbStruct.cs
- NegatedCellConstant.cs
- AdapterUtil.cs
- HtmlInputSubmit.cs
- DesignerVerbCollection.cs
- RegexCompilationInfo.cs
- ServiceModelActivity.cs
- GcSettings.cs
- GregorianCalendarHelper.cs
- XmlSerializationWriter.cs
- Input.cs
- ListViewDeletedEventArgs.cs
- WebServiceErrorEvent.cs
- DriveInfo.cs
- ScopeElementCollection.cs
- ProjectionPathSegment.cs
- PageBuildProvider.cs
- TextBounds.cs
- XmlAtomicValue.cs
- EventPrivateKey.cs
- MultipleViewPattern.cs
- ObjectItemCollection.cs
- storagemappingitemcollection.viewdictionary.cs
- IntPtr.cs
- DictionaryGlobals.cs
- SqlDataSourceCommandEventArgs.cs
- CodeCastExpression.cs
- TypedDataSourceCodeGenerator.cs
- DateTimeOffset.cs
- Keyboard.cs
- AttributeCollection.cs
- ReadOnlyNameValueCollection.cs
- RsaSecurityTokenAuthenticator.cs
- SkinBuilder.cs
- EntitySetBase.cs
- XPathItem.cs
- XamlPathDataSerializer.cs
- PrivilegedConfigurationManager.cs
- FixedTextView.cs
- XmlLoader.cs
- MethodCallTranslator.cs
- OleDbSchemaGuid.cs
- Nullable.cs
- HtmlSelect.cs
- PropertyTabChangedEvent.cs
- WindowsComboBox.cs
- RepeaterCommandEventArgs.cs
- BoundColumn.cs
- mediapermission.cs
- GPStream.cs
- CollectionDataContract.cs
- CodeArrayIndexerExpression.cs
- ColorConvertedBitmap.cs
- StylusPointDescription.cs
- DecimalAnimationBase.cs
- RuntimeConfigLKG.cs
- RadialGradientBrush.cs
- SQLInt16Storage.cs
- Compiler.cs
- FileChangesMonitor.cs
- ImplicitInputBrush.cs
- KeyMatchBuilder.cs
- MenuItemStyleCollection.cs
- ChannelServices.cs
- AnnotationComponentChooser.cs
- SqlIdentifier.cs
- EntityDataSourceUtil.cs
- SchemaEntity.cs
- DataGridViewIntLinkedList.cs
- SequentialWorkflowHeaderFooter.cs
- KeyTime.cs
- WebBrowser.cs
- DataGridViewColumnTypePicker.cs
- IBuiltInEvidence.cs
- SendMailErrorEventArgs.cs
- PictureBox.cs
- CategoryNameCollection.cs
- versioninfo.cs
- EditorPartCollection.cs
- iisPickupDirectory.cs
- QilGenerator.cs
- ButtonField.cs
- Dynamic.cs
- Matrix3DConverter.cs
- AvTrace.cs
- CipherData.cs
- BCryptSafeHandles.cs
- RelationshipWrapper.cs
- DataGridViewRowCollection.cs
- ListSortDescriptionCollection.cs
- WebPartConnectionsCancelVerb.cs
- VariantWrapper.cs
- StylusSystemGestureEventArgs.cs
- EntityContainerAssociationSet.cs