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
- SHA512.cs
- HostedTransportConfigurationManager.cs
- CaseStatementSlot.cs
- Image.cs
- ProcessModelInfo.cs
- StackOverflowException.cs
- StringUtil.cs
- XmlExceptionHelper.cs
- XmlSchemaInferenceException.cs
- SizeF.cs
- PointValueSerializer.cs
- XmlBinaryReaderSession.cs
- XmlBindingWorker.cs
- BaseParser.cs
- HybridObjectCache.cs
- ResourcePool.cs
- ContentFilePart.cs
- LicenseException.cs
- TemplateBuilder.cs
- TypeHelpers.cs
- UnlockCardRequest.cs
- Screen.cs
- EventLogPermissionEntryCollection.cs
- WebCategoryAttribute.cs
- StrokeCollectionConverter.cs
- UpdateExpressionVisitor.cs
- AssemblyBuilder.cs
- NetSectionGroup.cs
- adornercollection.cs
- XhtmlMobileTextWriter.cs
- BitmapEffect.cs
- DigitShape.cs
- ProcessManager.cs
- LoadWorkflowByKeyAsyncResult.cs
- OleDbDataAdapter.cs
- DetailsViewDeletedEventArgs.cs
- RuleSetDialog.Designer.cs
- x509utils.cs
- CompositeScriptReferenceEventArgs.cs
- ScriptingJsonSerializationSection.cs
- EnlistmentTraceIdentifier.cs
- VoiceInfo.cs
- StringWriter.cs
- InputLanguage.cs
- FileLogRecordHeader.cs
- IIS7UserPrincipal.cs
- StylusButtonEventArgs.cs
- BitmapEffectInputData.cs
- MSAAWinEventWrap.cs
- ErrorEventArgs.cs
- SoapSchemaImporter.cs
- ValidatorCompatibilityHelper.cs
- Brush.cs
- PLINQETWProvider.cs
- SqlProcedureAttribute.cs
- DefaultExpression.cs
- ViewCellRelation.cs
- ConstantSlot.cs
- Cursor.cs
- NotSupportedException.cs
- TextBox.cs
- DataGridColumnHeaderCollection.cs
- XmlSchemaExternal.cs
- XmlDataSourceView.cs
- SmtpTransport.cs
- ErrorFormatter.cs
- SignedInfo.cs
- XPathBinder.cs
- UIElement3D.cs
- SecurityHeaderLayout.cs
- BaseTemplateBuildProvider.cs
- SqlProcedureAttribute.cs
- ContextMarshalException.cs
- ToolStripItem.cs
- DispatchWrapper.cs
- ThrowHelper.cs
- ControlParameter.cs
- ConfigurationManagerHelper.cs
- HtmlTitle.cs
- PageFunction.cs
- ThemeableAttribute.cs
- EqualityArray.cs
- MimeMultiPart.cs
- UnsafeNativeMethods.cs
- TemplatedAdorner.cs
- ContainerParaClient.cs
- TrustSection.cs
- ColorContext.cs
- DataGridViewCellLinkedList.cs
- IgnoreFileBuildProvider.cs
- Control.cs
- CalendarDesigner.cs
- WebContext.cs
- HtmlTable.cs
- Int32RectConverter.cs
- WebPartTransformer.cs
- CodeMethodInvokeExpression.cs
- WaitHandle.cs
- ImagingCache.cs
- InvalidOperationException.cs