本文整理汇总了VB.NET中System.Collections.Concurrent.BlockingCollection<T>.GetConsumingEnumerable方法的典型用法代码示例。如果您正苦于以下问题:VB.NET BlockingCollection<T>.GetConsumingEnumerable方法的具体用法?VB.NET BlockingCollection<T>.GetConsumingEnumerable怎么用?VB.NET BlockingCollection<T>.GetConsumingEnumerable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Concurrent.BlockingCollection<T>
的用法示例。
在下文中一共展示了BlockingCollection<T>.GetConsumingEnumerable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: ConsumingEnumerableDemo
'Imports System.Threading.Tasks
'Imports System.Collections.Concurrent
' Demonstrates:
' BlockingCollection<T>.Add()
' BlockingCollection<T>.CompleteAdding()
' BlockingCollection<T>.GetConsumingEnumerable()
Class ConsumingEnumerableDemo
Shared Sub BC_GetConsumingEnumerable()
Using bc As New BlockingCollection(Of Integer)()
' Kick off a producer task
Task.Factory.StartNew(
Sub()
For i As Integer = 0 To 9
bc.Add(i)
' sleep 100 ms between adds
Thread.Sleep(100)
Next
' Need to do this to keep foreach below from not responding.
bc.CompleteAdding()
End Sub)
' Now consume the blocking collection with foreach.
' Use bc.GetConsumingEnumerable() instead of just bc because the
' former will block waiting for completion and the latter will
' simply take a snapshot of the current state of the underlying collection.
For Each item In bc.GetConsumingEnumerable()
Console.WriteLine(item)
Next
End Using
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Collections.Concurrent,代码行数:34,代码来源:BlockingCollection.GetConsumingEnumerable