techmanbd Posted November 28, 2007 Posted November 28, 2007 First here is my code. Question at the bottom. the sub that starts a test Private Sub startTest() If Me.chckIVFAT.Checked Then runTestThread(NAME_OF_SUB) End If If Me.chckIVFELO.Checked Then runTestThread(NAME_OF_SUB) End If If Me.chckIVDO.Checked Then runTestThread(NAME_OF_SUB) End If End sub the sub to do the thread Private Sub runTestThread(NAME_OF_SUB) thrdTest = New Thread(AddressOf NAME_OF_SUB) thrdTest.IsBackground = True thrdTest.Start() Do Application.DoEvents() Loop While thrdTest.ThreadState.Running End Sub So I don't have a LOT of lines of the thread, I made a sub to run the thread. How can I pass through the name of the sub to make the "addressof" for? I was thinking passing the name of the sub to start as a string, but how can I make sure the thread nows that is the sub I want to start as a thread? That is if that is a way to do it. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
mskeel Posted November 28, 2007 Posted November 28, 2007 You could pass the function pointer in directly rather than doing the addressof operation in runTestThread: runTestThread(AddressOf NAME_OF_SUB) Private Sub runTestThread(pointerToSub) thrdTest = New Thread(pointerToSub) thrdTest.IsBackground = True thrdTest.Start() Do Application.DoEvents() Loop While thrdTest.ThreadState.Running End Sub Quote
techmanbd Posted November 28, 2007 Author Posted November 28, 2007 Thanks for the reply. That is probably going into the right direction. But I do get an error with that. pointerToSub is what is giving me the error. I get this message 'AddressOf' expression cannot be converted to 'System.Object' because 'System.Object' is not a delegate type. So I probably to to make pointerToSub something other than an object, but can't find what to set it as. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
techmanbd Posted November 28, 2007 Author Posted November 28, 2007 Nevermind, I may have found it Private Sub runTestThread(pointerToSub as ThreadStart) I will give that a try and post later for success or more questions. Thanks for directing me in the right direction. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
techmanbd Posted November 28, 2007 Author Posted November 28, 2007 Re: Threading Question SUCCESS it works. thanks buddy. But did have to change this part Do Application.DoEvents() Loop While thrdTest.ThreadState.Running to this Do Application.DoEvents() Loop While thrdTest.isAlive as this would cause the code to keep going and then start the next thread at the same time. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.