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
- Int32KeyFrameCollection.cs
- XmlSchemaDatatype.cs
- CodeSnippetExpression.cs
- ClickablePoint.cs
- oledbconnectionstring.cs
- SystemWebCachingSectionGroup.cs
- SizeConverter.cs
- AccessDataSource.cs
- CodeNamespace.cs
- AffineTransform3D.cs
- Touch.cs
- FontWeights.cs
- FileNotFoundException.cs
- ActivityExecutionContextCollection.cs
- TypeDescriptionProvider.cs
- ResourceType.cs
- DelegateSerializationHolder.cs
- BaseHashHelper.cs
- VerificationAttribute.cs
- GenericEnumConverter.cs
- RegexInterpreter.cs
- FrameDimension.cs
- UxThemeWrapper.cs
- ReflectionServiceProvider.cs
- AttributeConverter.cs
- RC2.cs
- ClientRoleProvider.cs
- WinEventWrap.cs
- Vector3DKeyFrameCollection.cs
- Range.cs
- UnsafeNativeMethods.cs
- Geometry3D.cs
- CmsInterop.cs
- SSmlParser.cs
- GifBitmapDecoder.cs
- ErrorStyle.cs
- LogManagementAsyncResult.cs
- SessionStateContainer.cs
- GB18030Encoding.cs
- SrgsSubset.cs
- StringUtil.cs
- DispatcherOperation.cs
- HtmlHead.cs
- TraceXPathNavigator.cs
- StylusEventArgs.cs
- LayoutManager.cs
- SqlUserDefinedTypeAttribute.cs
- Annotation.cs
- TypeConverterAttribute.cs
- FontStretch.cs
- EntityPropertyMappingAttribute.cs
- EmbeddedMailObject.cs
- NetTcpSectionData.cs
- SurrogateSelector.cs
- ClientScriptItemCollection.cs
- BitmapEffectGeneralTransform.cs
- DataGridItemAutomationPeer.cs
- ChangeDirector.cs
- CollectionChangedEventManager.cs
- DeclarativeCatalogPartDesigner.cs
- ScrollBarRenderer.cs
- UrlMappingsSection.cs
- ZipIOExtraFieldPaddingElement.cs
- MediaContext.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- Rotation3DAnimationUsingKeyFrames.cs
- XPathItem.cs
- AsymmetricKeyExchangeFormatter.cs
- WorkflowEnvironment.cs
- KoreanLunisolarCalendar.cs
- RenderContext.cs
- TypeInitializationException.cs
- GuidConverter.cs
- PriorityBindingExpression.cs
- AxisAngleRotation3D.cs
- HttpModuleCollection.cs
- SmiEventSink.cs
- ExpandSegment.cs
- GroupDescription.cs
- CacheChildrenQuery.cs
- MD5.cs
- DataGridToolTip.cs
- PerformanceCounterPermissionAttribute.cs
- XmlNamespaceMappingCollection.cs
- MergePropertyDescriptor.cs
- CodeDelegateCreateExpression.cs
- AppDomainProtocolHandler.cs
- SQLChars.cs
- ResolveCompletedEventArgs.cs
- EventHandlerList.cs
- MetadataCache.cs
- FormViewCommandEventArgs.cs
- TypeSystem.cs
- ObjectPersistData.cs
- SpnegoTokenProvider.cs
- DeferredSelectedIndexReference.cs
- AxHost.cs
- SpoolingTaskBase.cs
- DataAdapter.cs
- Matrix3DValueSerializer.cs