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
- ImportCatalogPart.cs
- InternalResources.cs
- TableAdapterManagerHelper.cs
- BitConverter.cs
- CompositeDataBoundControl.cs
- PocoEntityKeyStrategy.cs
- TraceHelpers.cs
- ArgumentOutOfRangeException.cs
- CopyNamespacesAction.cs
- ClientSession.cs
- Visitors.cs
- AppDomainManager.cs
- HashHelper.cs
- UserUseLicenseDictionaryLoader.cs
- HttpHandlersSection.cs
- SystemIPInterfaceStatistics.cs
- C14NUtil.cs
- Material.cs
- PipeSecurity.cs
- PopupEventArgs.cs
- BitConverter.cs
- PeerToPeerException.cs
- SourceFilter.cs
- UpdateDelegates.Generated.cs
- ContextStack.cs
- OutputCacheModule.cs
- SafeRegistryHandle.cs
- AdRotatorDesigner.cs
- _UriSyntax.cs
- ContainerAction.cs
- ScrollChrome.cs
- LineMetrics.cs
- DNS.cs
- UnsafeNativeMethods.cs
- RemoveFromCollection.cs
- Header.cs
- FontStretch.cs
- Roles.cs
- ConsumerConnectionPointCollection.cs
- SqlClientFactory.cs
- TypeDependencyAttribute.cs
- View.cs
- CqlLexerHelpers.cs
- TextPenaltyModule.cs
- TCPListener.cs
- PathStreamGeometryContext.cs
- FileNotFoundException.cs
- ResourceDisplayNameAttribute.cs
- SqlCacheDependency.cs
- ObjectQuery.cs
- ImageField.cs
- WorkflowPrinting.cs
- ImageField.cs
- WorkflowQueue.cs
- ManagementPath.cs
- CheckBoxList.cs
- MethodAccessException.cs
- DataGridItem.cs
- SchemaTypeEmitter.cs
- RawStylusInputReport.cs
- XmlObjectSerializerWriteContext.cs
- Matrix3DStack.cs
- InkCanvas.cs
- DetailsViewModeEventArgs.cs
- InlinedAggregationOperatorEnumerator.cs
- ProcessStartInfo.cs
- PrimitiveXmlSerializers.cs
- EntityTypeBase.cs
- MethodSet.cs
- MimeReturn.cs
- DocumentCollection.cs
- HideDisabledControlAdapter.cs
- XmlChildNodes.cs
- CheckBoxFlatAdapter.cs
- SqlSelectClauseBuilder.cs
- MultiByteCodec.cs
- panel.cs
- InvalidCastException.cs
- StateBag.cs
- Form.cs
- CellLabel.cs
- QuaternionConverter.cs
- OleDbMetaDataFactory.cs
- PathSegmentCollection.cs
- TextDecorations.cs
- HttpProfileGroupBase.cs
- ObjectItemCollection.cs
- EntityException.cs
- KeyConstraint.cs
- Environment.cs
- DataQuery.cs
- FrugalList.cs
- FontSourceCollection.cs
- SymbolUsageManager.cs
- UnionExpr.cs
- CalendarButtonAutomationPeer.cs
- SmtpReplyReader.cs
- SmtpNtlmAuthenticationModule.cs
- ColorTransform.cs
- InfiniteIntConverter.cs