Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

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

Posted

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...