有些任务永远不会完成

时间:2015-11-01 04:37:41

标签: vb.net multithreading task-parallel-library task

我有一个与TPL有关的非常奇怪的问题。 我正在启动20个工作线程,它们都执行相同的方法:

'Note that "Items" is BlockingCollection
Private Async Function SomeTask() As Task
    While Not Items.IsCompleted
    Dim item As New Tuple(Of Item, Decimal)(New Item(), 0)
        If (Items.TryTake(item, 1000)) Then
            Try
                Dim ProcessedItem = Await DoSomethingAsync(item)
            Catch ex As Exception
                'Error catching, simplified for this post
            End Try
        End If
    End While
End Function

在一个主方法中,我在一组这些任务上使用等待Task.WhenAll。 20个任务中的19个正确完成,而1个卡住。我不知道这里可能出现什么问题,因为他们都在执行相同的操作。

0 个答案:

没有答案
相关问题