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
- SchemaTableColumn.cs
- BatchStream.cs
- sitestring.cs
- PerCallInstanceContextProvider.cs
- DictionaryTraceRecord.cs
- GlobalizationAssembly.cs
- HtmlInputHidden.cs
- PrivilegeNotHeldException.cs
- ProcessHostMapPath.cs
- ContextProperty.cs
- RegexParser.cs
- BasePattern.cs
- DynamicDocumentPaginator.cs
- ContextMenuStrip.cs
- AuthorizationRuleCollection.cs
- ExpandCollapseIsCheckedConverter.cs
- DetailsViewInsertedEventArgs.cs
- DesignerActionVerbList.cs
- TextRangeAdaptor.cs
- ViewGenerator.cs
- CharacterBufferReference.cs
- DomainConstraint.cs
- CompilationAssemblyInstallComponent.cs
- EdmPropertyAttribute.cs
- SecurityIdentifierElementCollection.cs
- DrawingVisual.cs
- URLIdentityPermission.cs
- WsiProfilesElement.cs
- CaseStatement.cs
- CharUnicodeInfo.cs
- LinearKeyFrames.cs
- InputLangChangeRequestEvent.cs
- TextControl.cs
- BitmapEffectGeneralTransform.cs
- RuntimeHelpers.cs
- NullableDoubleSumAggregationOperator.cs
- UnsafeNativeMethodsPenimc.cs
- PrimaryKeyTypeConverter.cs
- LongCountAggregationOperator.cs
- querybuilder.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- PeerChannelFactory.cs
- XPathBuilder.cs
- LineBreak.cs
- FixedSOMContainer.cs
- SqlConnectionManager.cs
- CodeNamespaceImportCollection.cs
- ConfigXmlWhitespace.cs
- AtomServiceDocumentSerializer.cs
- CacheOutputQuery.cs
- Int32CollectionValueSerializer.cs
- StandardToolWindows.cs
- CompareValidator.cs
- SettingsPropertyIsReadOnlyException.cs
- SqlCommandBuilder.cs
- ConfigXmlAttribute.cs
- MLangCodePageEncoding.cs
- RegistrySecurity.cs
- MaxMessageSizeStream.cs
- XmlSchemaComplexContentExtension.cs
- ButtonField.cs
- DataSourceSelectArguments.cs
- ColumnWidthChangingEvent.cs
- TextReturnReader.cs
- SqlLiftIndependentRowExpressions.cs
- RegionData.cs
- dataobject.cs
- ResourceProviderFactory.cs
- ParagraphVisual.cs
- CodePageEncoding.cs
- Debugger.cs
- SetStoryboardSpeedRatio.cs
- IisTraceWebEventProvider.cs
- PrincipalPermission.cs
- ValueTypePropertyReference.cs
- ValueSerializerAttribute.cs
- MessageDescription.cs
- AsyncDataRequest.cs
- AsyncInvokeContext.cs
- WindowAutomationPeer.cs
- ValidationHelper.cs
- SoapAttributeAttribute.cs
- CompositeDesignerAccessibleObject.cs
- XDeferredAxisSource.cs
- ColorKeyFrameCollection.cs
- LicFileLicenseProvider.cs
- Timer.cs
- XmlSerializerAssemblyAttribute.cs
- PartialCachingAttribute.cs
- AuthorizationRule.cs
- ConditionBrowserDialog.cs
- HtmlCalendarAdapter.cs
- SoapConverter.cs
- BufferedGraphicsManager.cs
- SqlCacheDependencySection.cs
- NavigationFailedEventArgs.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- RichTextBox.cs
- XmlComment.cs
- XmlNotation.cs