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
- SQLInt64.cs
- SqlInfoMessageEvent.cs
- _BasicClient.cs
- GradientSpreadMethodValidation.cs
- FixedFindEngine.cs
- ObjectPersistData.cs
- DispatcherHookEventArgs.cs
- PersistenceException.cs
- HyperLinkColumn.cs
- SymmetricKeyWrap.cs
- XDeferredAxisSource.cs
- SqlDependencyUtils.cs
- HtmlWindow.cs
- PagesSection.cs
- SHA1.cs
- Schema.cs
- IRCollection.cs
- Config.cs
- RuleConditionDialog.cs
- IPGlobalProperties.cs
- EntityViewGenerationConstants.cs
- XmlParser.cs
- DatagridviewDisplayedBandsData.cs
- SendKeys.cs
- ContourSegment.cs
- LingerOption.cs
- RepeatButtonAutomationPeer.cs
- AnonymousIdentificationSection.cs
- Decimal.cs
- ApplyTemplatesAction.cs
- DataControlButton.cs
- PresentationSource.cs
- BulletedList.cs
- Thickness.cs
- BamlVersionHeader.cs
- RuntimeCompatibilityAttribute.cs
- HttpStaticObjectsCollectionBase.cs
- SchemaTypeEmitter.cs
- PageStatePersister.cs
- MimeParameter.cs
- AttributeCollection.cs
- BamlVersionHeader.cs
- PrefixQName.cs
- ExpressionVisitor.cs
- CallContext.cs
- BooleanStorage.cs
- SoapCodeExporter.cs
- CodeBinaryOperatorExpression.cs
- ViewUtilities.cs
- GridViewDeletedEventArgs.cs
- XmlMemberMapping.cs
- Latin1Encoding.cs
- FaultDesigner.cs
- NamespaceListProperty.cs
- DataGridViewElement.cs
- ExpressionParser.cs
- PointKeyFrameCollection.cs
- TextEditorSpelling.cs
- Completion.cs
- TemplatedControlDesigner.cs
- FontWeight.cs
- MetadataItemCollectionFactory.cs
- ObjectConverter.cs
- InheritedPropertyChangedEventArgs.cs
- QilGeneratorEnv.cs
- PrintPreviewControl.cs
- SymLanguageType.cs
- SafeLibraryHandle.cs
- MenuAutomationPeer.cs
- WinFormsComponentEditor.cs
- XPathAncestorIterator.cs
- DataSourceXmlTextReader.cs
- IndentTextWriter.cs
- TreeWalker.cs
- DataGridBeginningEditEventArgs.cs
- Color.cs
- ScrollViewer.cs
- PropertyValueChangedEvent.cs
- TailPinnedEventArgs.cs
- NotCondition.cs
- BaseResourcesBuildProvider.cs
- ServicesUtilities.cs
- QilGenerator.cs
- JsonDataContract.cs
- SamlSubject.cs
- Context.cs
- DataGridTextBox.cs
- DiscoveryDocumentLinksPattern.cs
- TrackingMemoryStream.cs
- OleDbErrorCollection.cs
- LinqDataView.cs
- OpenTypeLayoutCache.cs
- Gdiplus.cs
- TrackingProfile.cs
- EditingScope.cs
- ChtmlCalendarAdapter.cs
- LinkDescriptor.cs
- StylusButtonCollection.cs
- SecurityAlgorithmSuiteConverter.cs
- CodeSubDirectory.cs