Try Dim tasks As New List(Of Task)() For Each drv In drives Dim currentDrive As Drive = drv If drv.IsReady Then Dim readTask As New Task(Sub() queryDrive(currentDrive) End Sub, TaskCreationOptions.LongRunning) tasks.Add(readTask) readTask.Start() End If Next 'Task.WaitAll(tasks.ToArray()) timerTotalMsStopwatch.Stop() btnGetComputers.Enabled = True btnCancel.Enabled = False Dim msg As String = String.Format("{0} files ({1:0} Sec).", files.Count, timerTotalMsStopwatch.ElapsedMilliseconds / 1000) SetUIText(msg, msg & vbCrLf) Catch ex As Exception MsgBox(String.Format("{0}", ex.StackTrace), MsgBoxStyle.Critical, "Error") End Try
WaitAll
Async
Await Task.WhenAll(tasks)
Task.WaitAll(...)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)