问题: 我正在编写一个类来简化对新线程的管理。我试图间接引用我要在其中运行新线程的类。这样,对于该类的每个实例,我都可以管理不同的代码和线程块。
'-----------------------------------
我尝试过的方法: 我一直在研究几个小时的不同选择,我能找到的最好的是CallByName,但我无法使它正常工作。
我一直在尝试的不同变体
Private THREAD_OBJECT As New Thread(AddressOf CallByName(various combinations of params))
并且没有成功。
'-----------------------------------
此代码将创建一个名为{name I pass it}的新线程,该线程在子例程ENTRY_POINT中的CLASS_TO_RUN类中运行
Public Class THREAD_MANAGEMENT
Private CLASS_TO_RUN As New NEW_THREAD_CLASS() 'Create an instance of the class where the new thread will run.
Private THREAD_OBJECT As New Thread(AddressOf CLASS_TO_RUN.ENTRY_POINT) 'Create object.
Public Function CREATE_THREAD(ByVal NAME As String) As Boolean
With THREAD_OBJECT
.Name = NAME 'Name the thread.
.Start() 'Start the thread.
End With
Return True 'Just return true for now, will add more ops later.
End Function
Public Function KILL_THREAD() As Boolean
Try
THREAD_OBJECT.Abort() 'Kill the thread running in the other class.
Catch EXCEPTION As ThreadAbortException 'Catch the exception generated by murdering a thread.
End Try
Return True 'Just return true for now, will add more ops later.
End Function
End Class
'-----------------------------------
此代码有效,只是我不能更改线程的位置。我在这里不了解线程管理和间接引用。任何帮助将不胜感激。