我的表单需要一点(或很大)帮助:我需要在单独的线程中使用“组织功能”区域内的所有内容。
我在表单的“开始按钮”区域中按下一个按钮来调用“组织功能”子程序的第一个子程序;第一个子调用第二个子,第二个子调用第三个子。
我尝试自己将第三个子添加到单独的线程中,然后使用第二个子将参数传递给线程,但我所做的一切都是错误的。
有人可以帮我这样做吗?
PS:我已经删除了这个表格中不重要的部分,以便您更好地检查。
感谢您的阅读。
Public Class Form1
#Region "Declarations"
' MediaInfo
Dim MI As MediaInfo
' Thread
Dim paused As Boolean = False
' Others
Dim NameOfDirectory As String = Nothing
Dim aFile As FileInfo
#End Region
'thread
Dim t As New Thread(AddressOf ThreadProc)
Public Sub ThreadProc()
' Aqui debería ir todo el sub de "organize function", bueno... son 3 subs!
If paused = True Then MsgBox("THREAD PAUSADO")
End Sub
#Region "Properties"
...
#End Region
#Region "Load / Close"
...
#End Region
#Region "Get Total files Function"
...
#End Region
#Region "Option checkboxes"
...
#End Region
#Region "Folder buttons"
...
#End Region
#Region "Append text function"
...
#End Region
#Region "Action buttons"
' pause button
Private Sub pause_button_Click(sender As Object, e As EventArgs) Handles pause_button.Click
paused = True
End Sub
' start button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles start_button.Click
t.Start()
' Organization process
NameOfDirectory = userSelectedFolderPath
MediaInfo(NameOfDirectory)
End Sub
#End region
#Region "Organize function"
Public Sub MediaInfo(Directory)
Dim MyDirectory As DirectoryInfo
MyDirectory = New DirectoryInfo(NameOfDirectory)
MediaInfoWorkWithDirectory(MyDirectory)
End Sub
Public Sub MediaInfoWorkWithDirectory(ByVal aDir As DirectoryInfo)
Dim nextDir As DirectoryInfo
MediaInfoWorkWithFilesInDir(aDir)
For Each nextDir In aDir.GetDirectories
Using writer As StreamWriter = New StreamWriter(aDir.FullName & "\" & nextDir.Name & "\" & nextDir.Name & ".m3u", False, System.Text.Encoding.UTF8)
'overwrite existing playlist
End Using
MediaInfoWorkWithDirectory(nextDir)
Next
End Sub
Public Sub MediaInfoWorkWithFilesInDir(ByVal aDir As DirectoryInfo)
Dim aFile As FileInfo
For Each aFile In aDir.GetFiles()
' hacer cosas con aFile ...
Next
End Sub
#End Region
End Class