Code:
/ 4.0 / 4.0 / 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 IEnumerableWrap (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. // ==++== // // 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 IEnumerableWrap (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
- IdnElement.cs
- TextFormatterImp.cs
- FunctionMappingTranslator.cs
- RootProfilePropertySettingsCollection.cs
- SQLGuid.cs
- TextElement.cs
- CustomErrorCollection.cs
- RepeatInfo.cs
- UrlMapping.cs
- CodeTypeMember.cs
- HtmlEmptyTagControlBuilder.cs
- ListDataHelper.cs
- SendActivityValidator.cs
- UriScheme.cs
- Viewport2DVisual3D.cs
- OptimizerPatterns.cs
- filewebrequest.cs
- ProfilePropertyMetadata.cs
- NotFiniteNumberException.cs
- DiscoveryDefaults.cs
- AttachmentCollection.cs
- ModuleBuilder.cs
- RequiredFieldValidator.cs
- Pair.cs
- SelectionEditor.cs
- BrowsableAttribute.cs
- ReferenceSchema.cs
- CriticalHandle.cs
- TraceRecord.cs
- WindowsTab.cs
- Int16AnimationUsingKeyFrames.cs
- VisualTarget.cs
- ContentOperations.cs
- entityreference_tresulttype.cs
- XmlAnyElementAttribute.cs
- ImageInfo.cs
- PropertyToken.cs
- SoapSchemaMember.cs
- SuppressMergeCheckAttribute.cs
- InstanceValue.cs
- ViewService.cs
- Normalizer.cs
- Subtree.cs
- Vector.cs
- AdCreatedEventArgs.cs
- MinMaxParagraphWidth.cs
- ContainerParaClient.cs
- IListConverters.cs
- CharEntityEncoderFallback.cs
- WebReferenceCollection.cs
- DeobfuscatingStream.cs
- ProxyBuilder.cs
- CatalogPartCollection.cs
- Rect.cs
- FacetValues.cs
- PropertyHelper.cs
- Package.cs
- XmlDataSourceView.cs
- SystemIPv4InterfaceProperties.cs
- EntityDataSourceQueryBuilder.cs
- TaskExceptionHolder.cs
- CodeAccessSecurityEngine.cs
- ConstructorNeedsTagAttribute.cs
- securitycriticaldata.cs
- MailDefinitionBodyFileNameEditor.cs
- Propagator.cs
- DataFormats.cs
- TemplateBindingExtensionConverter.cs
- SourceLineInfo.cs
- DesignerActionVerbItem.cs
- ListArgumentProvider.cs
- HtmlImage.cs
- cryptoapiTransform.cs
- ProgressBarHighlightConverter.cs
- CharacterBufferReference.cs
- MembershipUser.cs
- ByteRangeDownloader.cs
- ChtmlTextWriter.cs
- SafeHandles.cs
- DocumentEventArgs.cs
- TdsEnums.cs
- XmlConvert.cs
- SqlDependency.cs
- ProcessHostConfigUtils.cs
- FontSource.cs
- FormView.cs
- ZipIOLocalFileBlock.cs
- LinqDataSourceEditData.cs
- WebServiceEnumData.cs
- VerticalAlignConverter.cs
- DrawingCollection.cs
- Win32SafeHandles.cs
- Peer.cs
- PropertyMetadata.cs
- smtppermission.cs
- ModelFunction.cs
- RowUpdatedEventArgs.cs
- PermissionListSet.cs
- ADRole.cs
- PackUriHelper.cs