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
- BitmapCodecInfoInternal.cs
- ItemCollection.cs
- TextDecoration.cs
- TraceHandlerErrorFormatter.cs
- UnsafeNativeMethods.cs
- webeventbuffer.cs
- SafeArrayTypeMismatchException.cs
- GeometryValueSerializer.cs
- CollectionAdapters.cs
- _AutoWebProxyScriptWrapper.cs
- DataControlFieldCell.cs
- NavigationPropertyEmitter.cs
- CollectionChangeEventArgs.cs
- HexParser.cs
- DrawingImage.cs
- SqlRewriteScalarSubqueries.cs
- ObjRef.cs
- CachedFontFace.cs
- TargetFrameworkAttribute.cs
- PropertyValueUIItem.cs
- TraceHwndHost.cs
- HttpModule.cs
- LogReservationCollection.cs
- KeyValuePair.cs
- CDSsyncETWBCLProvider.cs
- DataGridViewColumnCollection.cs
- ModelUIElement3D.cs
- FileChangesMonitor.cs
- SurrogateChar.cs
- UserControl.cs
- NativeMethods.cs
- CriticalExceptions.cs
- ReferencedType.cs
- BindingExpressionUncommonField.cs
- CheckBoxField.cs
- CannotUnloadAppDomainException.cs
- ClientFormsIdentity.cs
- WmpBitmapEncoder.cs
- ThrowOnMultipleAssignment.cs
- ProcessThreadCollection.cs
- EmbeddedMailObjectsCollection.cs
- PersonalizationProvider.cs
- ProxyHelper.cs
- SecurityResources.cs
- HiddenField.cs
- TraceContextRecord.cs
- HttpPostedFile.cs
- FileStream.cs
- HealthMonitoringSection.cs
- CertificateManager.cs
- UserControl.cs
- InstanceStoreQueryResult.cs
- DocumentAutomationPeer.cs
- SoapProtocolReflector.cs
- SelfSignedCertificate.cs
- FixedSOMTable.cs
- Matrix3D.cs
- AdvancedBindingEditor.cs
- StylusPointPropertyInfo.cs
- SimpleMailWebEventProvider.cs
- TextHintingModeValidation.cs
- CompilerScopeManager.cs
- ComNativeDescriptor.cs
- Propagator.JoinPropagator.cs
- DbConnectionPoolCounters.cs
- FrameworkElementFactoryMarkupObject.cs
- ManifestResourceInfo.cs
- GuidConverter.cs
- PeerTransportCredentialType.cs
- MenuStrip.cs
- PropertyInformation.cs
- DesignTimeTemplateParser.cs
- ClientSettingsStore.cs
- HttpCookieCollection.cs
- ControlBuilder.cs
- CellTreeNodeVisitors.cs
- TimeIntervalCollection.cs
- ManagementInstaller.cs
- BStrWrapper.cs
- EventSourceCreationData.cs
- FormViewPageEventArgs.cs
- XmlSchema.cs
- SocketInformation.cs
- DataBindingHandlerAttribute.cs
- RoleGroup.cs
- DropSourceBehavior.cs
- ToolStripContentPanel.cs
- _AutoWebProxyScriptHelper.cs
- ShapingEngine.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- VirtualDirectoryMapping.cs
- storepermissionattribute.cs
- Recipient.cs
- Int32Converter.cs
- DeclarativeConditionsCollection.cs
- AuthenticationSchemesHelper.cs
- RandomNumberGenerator.cs
- RuleSetReference.cs
- SocketPermission.cs
- RecognitionResult.cs