Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Utils / CancellableEnumerable.cs / 1305376 / CancellableEnumerable.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// CancellableEnumerable.cs
//
// [....]
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Linq.Parallel;
namespace System.Linq.Parallel
{
internal static class CancellableEnumerable
{
///
/// Wraps an enumerable with a cancellation checker. The enumerator handed out by the source enumerable
/// will be wrapped by an object that periodically checks whether a particular cancellation token has
/// been cancelled. If so, the next call to MoveNext() will throw an OperationCancelledException.
///
internal static IEnumerable Wrap(IEnumerable source, CancellationToken token)
{
int count = 0;
foreach (TElement element in source)
{
if ((count++ & CancellationState.POLL_INTERVAL) == 0)
CancellationState.ThrowIfCanceled(token);
yield return element;
}
}
}
}
// 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
- GridViewColumnHeader.cs
- ColorAnimationBase.cs
- MeasureItemEvent.cs
- PrintPreviewControl.cs
- MemoryRecordBuffer.cs
- DataGridViewRowCancelEventArgs.cs
- SqlMetaData.cs
- MarkupProperty.cs
- InstanceHandle.cs
- controlskin.cs
- SingleResultAttribute.cs
- SqlDuplicator.cs
- GetWinFXPath.cs
- TransactionState.cs
- BuildProvidersCompiler.cs
- ArrayWithOffset.cs
- SelectedGridItemChangedEvent.cs
- Literal.cs
- BackgroundFormatInfo.cs
- ObjectListFieldCollection.cs
- OutputCacheSettings.cs
- GrammarBuilderPhrase.cs
- KnownColorTable.cs
- BamlWriter.cs
- HttpResponseHeader.cs
- CodeSubDirectory.cs
- StretchValidation.cs
- SecurityTokenRequirement.cs
- FixedElement.cs
- CapabilitiesUse.cs
- FormViewUpdatedEventArgs.cs
- SqlProcedureAttribute.cs
- HwndSubclass.cs
- CurrencyManager.cs
- Nullable.cs
- MembershipValidatePasswordEventArgs.cs
- HttpRuntime.cs
- UIElement3D.cs
- CatalogPart.cs
- HMACMD5.cs
- ResourceWriter.cs
- IOThreadTimer.cs
- ColumnResult.cs
- MarkedHighlightComponent.cs
- SvcMapFileLoader.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- CanExecuteRoutedEventArgs.cs
- WindowsSlider.cs
- SizeChangedEventArgs.cs
- SystemSounds.cs
- XmlNodeList.cs
- DataGridViewCheckBoxCell.cs
- EncoderFallback.cs
- NativeMethods.cs
- ReadOnlyTernaryTree.cs
- NonSerializedAttribute.cs
- ComplexBindingPropertiesAttribute.cs
- StorageAssociationSetMapping.cs
- TrustLevel.cs
- ButtonPopupAdapter.cs
- ExtendedPropertyInfo.cs
- StatusBarItemAutomationPeer.cs
- AdapterUtil.cs
- SqlDependencyListener.cs
- ReadOnlyDataSource.cs
- CommandSet.cs
- HtmlElement.cs
- TypeUtil.cs
- Main.cs
- StorageModelBuildProvider.cs
- EditorAttribute.cs
- SystemWebExtensionsSectionGroup.cs
- CodeAttributeDeclarationCollection.cs
- StsCommunicationException.cs
- InputBinding.cs
- SectionRecord.cs
- sqlmetadatafactory.cs
- DesignOnlyAttribute.cs
- ColorKeyFrameCollection.cs
- OrderedDictionary.cs
- IsolationInterop.cs
- GridViewRowCollection.cs
- SponsorHelper.cs
- NameObjectCollectionBase.cs
- PeerNameRegistration.cs
- XmlSchemaAnnotated.cs
- MeasurementDCInfo.cs
- EntityKeyElement.cs
- UpdateManifestForBrowserApplication.cs
- DataContractJsonSerializer.cs
- WeakEventTable.cs
- ActiveXContainer.cs
- TraceContextRecord.cs
- RectAnimationClockResource.cs
- PeerObject.cs
- HashCodeCombiner.cs
- CustomAssemblyResolver.cs
- SingleBodyParameterMessageFormatter.cs
- MonitorWrapper.cs
- EntityProviderFactory.cs