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
- UnsafePeerToPeerMethods.cs
- _NTAuthentication.cs
- Timer.cs
- CounterSet.cs
- VariableAction.cs
- FileUtil.cs
- WebBrowserUriTypeConverter.cs
- DbConnectionFactory.cs
- ProvideValueServiceProvider.cs
- ContractCodeDomInfo.cs
- Compiler.cs
- NativeMethods.cs
- NativeBuffer.cs
- ActionFrame.cs
- SafeNativeMethods.cs
- ExpandCollapsePattern.cs
- AnnotationHighlightLayer.cs
- RequestStatusBarUpdateEventArgs.cs
- FormsAuthenticationUser.cs
- Vector3DAnimation.cs
- GcSettings.cs
- SqlAggregateChecker.cs
- FileDialogCustomPlacesCollection.cs
- COM2EnumConverter.cs
- ModifiableIteratorCollection.cs
- CreateWorkflowOwnerCommand.cs
- DataGridTemplateColumn.cs
- ExpressionBuilder.cs
- Hyperlink.cs
- VisualTreeHelper.cs
- WmfPlaceableFileHeader.cs
- CapabilitiesUse.cs
- COM2ComponentEditor.cs
- WCFBuildProvider.cs
- CategoryEditor.cs
- WebPartDisplayModeEventArgs.cs
- ReaderContextStackData.cs
- PrimitiveXmlSerializers.cs
- SystemPens.cs
- QueryReaderSettings.cs
- OleDbConnection.cs
- DESCryptoServiceProvider.cs
- PartialCachingControl.cs
- TileModeValidation.cs
- FixedPageStructure.cs
- listitem.cs
- WindowsFont.cs
- ColorConverter.cs
- SkinIDTypeConverter.cs
- ViewValidator.cs
- SqlMethodCallConverter.cs
- RouteParameter.cs
- ZipIOLocalFileBlock.cs
- SecureUICommand.cs
- SkewTransform.cs
- CodeDomDesignerLoader.cs
- DataShape.cs
- Tokenizer.cs
- IndexedString.cs
- SqlParameter.cs
- EntitySqlQueryCacheKey.cs
- DataSourceCache.cs
- TypeForwardedToAttribute.cs
- SharedHttpsTransportManager.cs
- SqlFunctions.cs
- TimeEnumHelper.cs
- _DisconnectOverlappedAsyncResult.cs
- PaintValueEventArgs.cs
- ToolboxItemCollection.cs
- DSACryptoServiceProvider.cs
- WebPartDeleteVerb.cs
- SqlSupersetValidator.cs
- DesignerAutoFormat.cs
- mactripleDES.cs
- PrinterSettings.cs
- Pts.cs
- NetworkInformationPermission.cs
- XamlInt32CollectionSerializer.cs
- RawMouseInputReport.cs
- ComplexObject.cs
- FormatPage.cs
- SecurityBindingElement.cs
- XamlPointCollectionSerializer.cs
- BindUriHelper.cs
- Socket.cs
- XmlILConstructAnalyzer.cs
- SecurityCriticalDataForSet.cs
- DetailsViewInsertEventArgs.cs
- Material.cs
- ToolStripPanel.cs
- ExceptionUtil.cs
- StyleTypedPropertyAttribute.cs
- TransformedBitmap.cs
- BindingExpression.cs
- TypeConstant.cs
- SqlDataSourceQueryEditor.cs
- ClaimTypes.cs
- XmlNodeChangedEventArgs.cs
- DataServiceHostWrapper.cs
- NetTcpBindingElement.cs