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
- WebProxyScriptElement.cs
- PeerSecurityHelpers.cs
- BindableTemplateBuilder.cs
- PropertyItemInternal.cs
- CodeDOMUtility.cs
- GridToolTip.cs
- ProviderBase.cs
- NTAccount.cs
- SqlCharStream.cs
- CodeBlockBuilder.cs
- FileEnumerator.cs
- MulticastDelegate.cs
- PrintEvent.cs
- FontStyles.cs
- ProcessModelInfo.cs
- precedingquery.cs
- StylusDevice.cs
- _ConnectOverlappedAsyncResult.cs
- XmlNamespaceMappingCollection.cs
- XmlSchemaInclude.cs
- ReadOnlyDictionary.cs
- ConnectorEditor.cs
- XmlNodeReader.cs
- SqlConnectionPoolGroupProviderInfo.cs
- Slider.cs
- RecommendedAsConfigurableAttribute.cs
- MenuEventArgs.cs
- ByteAnimationBase.cs
- EventManager.cs
- Base64Decoder.cs
- WorkflowFileItem.cs
- HttpRuntime.cs
- MetadataItemSerializer.cs
- SizeAnimation.cs
- MemberRestriction.cs
- XmlSignificantWhitespace.cs
- BindingBase.cs
- HttpBrowserCapabilitiesWrapper.cs
- InputLanguage.cs
- BinaryReader.cs
- Operator.cs
- Error.cs
- FormsAuthenticationConfiguration.cs
- StringResourceManager.cs
- ProcessRequestAsyncResult.cs
- LinkTarget.cs
- SchemaTableOptionalColumn.cs
- ExpressionLink.cs
- ObjectDataSourceFilteringEventArgs.cs
- ISAPIApplicationHost.cs
- ToolStrip.cs
- ProcessModuleDesigner.cs
- TypeCodeDomSerializer.cs
- ArgumentNullException.cs
- CheckPair.cs
- DetailsViewPageEventArgs.cs
- WorkflowFileItem.cs
- AdapterSwitches.cs
- WindowsGrip.cs
- StretchValidation.cs
- Comparer.cs
- ProxyWebPartConnectionCollection.cs
- Int32Rect.cs
- BamlVersionHeader.cs
- ListControlConvertEventArgs.cs
- SizeChangedEventArgs.cs
- TimeSpan.cs
- ColumnTypeConverter.cs
- TextRangeBase.cs
- CompositeDuplexElement.cs
- Point3DCollectionConverter.cs
- ProcessModuleCollection.cs
- _HTTPDateParse.cs
- MessageDecoder.cs
- WebPart.cs
- ApplicationManager.cs
- XmlComment.cs
- ListViewTableRow.cs
- CalendarDayButton.cs
- Resources.Designer.cs
- RoleManagerEventArgs.cs
- WebPartPersonalization.cs
- PolyBezierSegmentFigureLogic.cs
- ThreadPool.cs
- AdvancedBindingPropertyDescriptor.cs
- XmlName.cs
- ToolTipAutomationPeer.cs
- HashCodeCombiner.cs
- RelatedPropertyManager.cs
- DWriteFactory.cs
- EntitySet.cs
- SettingsPropertyNotFoundException.cs
- UriTemplateVariableQueryValue.cs
- UTF8Encoding.cs
- GridView.cs
- LocalServiceSecuritySettingsElement.cs
- InputGestureCollection.cs
- LogSwitch.cs
- XsltArgumentList.cs
- ProcessModuleCollection.cs