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
- XPathNodeHelper.cs
- ParserStreamGeometryContext.cs
- MediaScriptCommandRoutedEventArgs.cs
- WindowsRebar.cs
- ListItemConverter.cs
- WebPartEventArgs.cs
- DataFieldCollectionEditor.cs
- ADRole.cs
- CriticalFinalizerObject.cs
- HttpResponseHeader.cs
- ComponentEvent.cs
- _AcceptOverlappedAsyncResult.cs
- NullableLongAverageAggregationOperator.cs
- ListMarkerSourceInfo.cs
- NavigatorOutput.cs
- RuleSettings.cs
- HelpFileFileNameEditor.cs
- RecognizedAudio.cs
- HandlerWithFactory.cs
- CSharpCodeProvider.cs
- XmlUnspecifiedAttribute.cs
- UpdateCompiler.cs
- IndexingContentUnit.cs
- ExpressionDumper.cs
- EntityDesignerDataSourceView.cs
- Brush.cs
- DesignerSerializationVisibilityAttribute.cs
- typedescriptorpermissionattribute.cs
- X509Certificate.cs
- IgnoreFileBuildProvider.cs
- UnauthorizedWebPart.cs
- GeometryGroup.cs
- DataGridColumnHeader.cs
- DecimalConverter.cs
- HyperLinkStyle.cs
- SafeFileHandle.cs
- StrongName.cs
- SchemaCollectionCompiler.cs
- DES.cs
- ObjectConverter.cs
- SendMailErrorEventArgs.cs
- VectorCollectionValueSerializer.cs
- CodeDomConfigurationHandler.cs
- Tracer.cs
- ProfessionalColorTable.cs
- ResolveRequestResponseAsyncResult.cs
- ServiceOperationInvoker.cs
- pingexception.cs
- BamlLocalizer.cs
- RectangleGeometry.cs
- StrokeNodeData.cs
- SQLBytesStorage.cs
- PerformanceCounter.cs
- PrintDialog.cs
- XmlSchema.cs
- SingleSelectRootGridEntry.cs
- ReachPrintTicketSerializer.cs
- TriggerActionCollection.cs
- SoapAttributeOverrides.cs
- Parser.cs
- XpsColorContext.cs
- LocalFileSettingsProvider.cs
- WindowProviderWrapper.cs
- PassportAuthenticationModule.cs
- DetailsViewRowCollection.cs
- ExpressionEditor.cs
- TextContainer.cs
- ReadOnlyCollectionBase.cs
- TemplateBuilder.cs
- MimeTextImporter.cs
- ServiceHttpModule.cs
- CellParaClient.cs
- MembershipSection.cs
- SerializationObjectManager.cs
- IPCCacheManager.cs
- Html32TextWriter.cs
- ColorConvertedBitmap.cs
- XmlSchemaSimpleContentExtension.cs
- ValueTypeFixupInfo.cs
- PrintDialogException.cs
- HttpApplicationFactory.cs
- DynamicQueryableWrapper.cs
- GridViewRowPresenterBase.cs
- DeviceContext.cs
- ParsedAttributeCollection.cs
- ListControlStringCollectionEditor.cs
- WindowsImpersonationContext.cs
- SqlStatistics.cs
- FlowLayout.cs
- RepeatButtonAutomationPeer.cs
- CalendarDateRange.cs
- Native.cs
- CommandDesigner.cs
- QueryExpression.cs
- SqlLiftIndependentRowExpressions.cs
- WebResourceAttribute.cs
- LogAppendAsyncResult.cs
- SharedStatics.cs
- Camera.cs
- WeakReadOnlyCollection.cs