Thread process with arguments

G

Guest

Hi,

I used thread to start a process which needs one or more arguments, my
question is who to call the function from a thead? My codes are following:

Private Sub myProcess(ByVal max as integer)
Dim i As Integer
For i = 0 To max
Threading.Thread.Sleep(100)
Next
End Sub

Dim tdProcess As Threading.Thread = New Threading.Thread(AddressOf myProcess)
tdProcess.Start()
 
C

Cor Ligthert

Li Pang,

As I do it is

Create a class for your extra thread

And than

\\\the most is typed in this message so watch typos
Dim MyExtraThread as New clsExtraThread(threadInfo)
dim ExThread as New System.Threading.Thread(AddressOf
MyExtraThread.TheMethod)
ExThread.Start()
///

I hope this helps?

Cor
 
G

Guest

Cor,

I understood that you suggested to pass the arguments through a class
initialization. It worked well. But I'd like to pass the arguments through
the Sub/Function itself. Is that possible?

Thanks for your effort.
 
C

Cor Ligthert

Li,

I don't know I do it this way, however you can as well set a global
variable.

I hope this helps?

Cor
 
G

Guest

Use Delegate.BeginInvoke method:
Public Delegate Sub myDelegateABC(ByVal strA As String, ByVal intB As
Integer)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myDelegate As New myDelegateABC(AddressOf ABC)
myDelegate.BeginInvoke("ABC-StrA", 100, Nothing, Nothing)

End Sub
Private Sub ABC(ByVal strA As String, ByVal intB As Integer)
MsgBox(strA + intB.ToString)
End Sub
 
C

Cor Ligthert

Li,

Can you point me in this message where is the answer on your question.
I understood that you suggested to pass the arguments through a class
initialization. It worked well. But I'd like to pass the arguments through
the Sub/Function itself. Is that possible?

I do not see it, for the rest it is a long article, however the solution for
your first question
I used thread to start a process which needs one or more arguments, my
question is who to call the function from a thead?

Is as far as I can see the same as I gave you (without the global variable
setting on your first question).

For passing back you have never asked.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top