我不是vb.net的專家,所以這對我來說是一個令人沮喪的問題。我需要從目錄中讀取圖像並且並行處理它們。因此理想的代碼應該是,每次在vb.net傳遞一個對象到一個循環中的線程
Dim Directory As New IO.DirectoryInfo("New Folder\\")
Dim allFiles As IO.FileInfo() = Directory.GetFiles("*.bmp")
Dim singleFile As IO.FileInfo
Dim i As Integer = 0
For Each singleFile In allFiles
Console.WriteLine(singleFile.FullName)
If File.Exists(singleFile.FullName) Then
Dim badge As Image(Of Bgr, Byte) = New Image(Of Bgr, Byte) (singleFile.FullName)
i = i + 1
Dim checkLabelThread As Thread = New Thread(AddressOf processBadge(badge, i))
End If
Next`
在這裏,processBadge是應該處理徽章的函數。但Vb.net不允許我將變量傳遞給該函數。有沒有解決這個問題並滿足我的要求的工作?非常感謝。
爲了讓它編譯(並且假設你的'Image(Of T1,T2)'甚至是一個真正的類型),你只需要改變'AddressOf'到'Sub()'。然而,這整個事情需要重新思考:循環內部的遺忘線程?聽起來不是一個好主意。 –