diff --git a/Parallel/ThreadTask/ThreadTask.vb b/Parallel/ThreadTask/ThreadTask.vb
index 121d1f0..17c0bdd 100644
--- a/Parallel/ThreadTask/ThreadTask.vb
+++ b/Parallel/ThreadTask/ThreadTask.vb
@@ -65,6 +65,13 @@ Namespace ThreadTask
ReadOnly debugMode As Boolean = False
ReadOnly verbose As Boolean = True
+ '''
+ ''' sleep for a interval between start each parallel
+ ''' task thread could avoid some parallel lock
+ ''' problem.
+ '''
+ ReadOnly taskInterval As Integer = 1000
+
'''
''' create parallel task pool from a given collection of task handler
'''
@@ -74,12 +81,14 @@ Namespace ThreadTask
'''
Sub New(task As IEnumerable(Of Func(Of TOut)),
Optional debugMode As Boolean = False,
- Optional verbose As Boolean = True)
+ Optional verbose As Boolean = True,
+ Optional taskInterval As Integer = 1500)
Me.taskList = New Queue(Of Func(Of TOut))(task)
Me.size = Me.taskList.Count
Me.verbose = verbose
Me.debugMode = debugMode
+ Me.taskInterval = taskInterval
End Sub
'''
@@ -177,11 +186,13 @@ Namespace ThreadTask
End Function
Private Iterator Function ParallelTask() As IEnumerable(Of TOut)
+ ' handling all pending task
Do While taskList.Count > 0
Dim i As Integer = GetEmptyThread()
If i > -1 Then
threads(i) = New AsyncHandle(Of TOut)(taskList.Dequeue).Run
+ Thread.Sleep(taskInterval)
End If
Dim j As Integer = GetCompleteThread()
@@ -196,9 +207,10 @@ Namespace ThreadTask
threads(j) = Nothing
End If
- Call Thread.Sleep(1)
+ Call Thread.Sleep(100)
Loop
+ ' wait for all remaining task finished
Do While Not threads.All(Function(t) t Is Nothing)
Dim j As Integer = GetCompleteThread()
@@ -212,7 +224,7 @@ Namespace ThreadTask
threads(j) = Nothing
End If
- Call Thread.Sleep(1)
+ Call Thread.Sleep(100)
Loop
End Function
End Class