# Call a function with parameters by a thread in vb.net 2.0

Hi,
I have a function
Public Function Get_SQL_Line(ByRef SQL As String, ByRef reader As IO.StreamReader)
end function
I want to strat it with a thread .How can I do this?

Cheers
###### Who is Participating?

Commented:
I'm not sure why you would want to run threads inside such a tight loop. Aside from that, you would be trying to access a shared reader which may lead to unreliable results.
0

Commented:
Because you have the parameters, you will either have to call a intermediary function to call this function or create a structure to hold the parameter info.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

th.Start()
End Sub

Private Sub Work()
End Sub

''''''''''''''''''''''' OR '''''''''''''''''''''''''

Public Function Get_SQL_Line(ByRef parameter As Object)
If TypeOf parameter Is ThreadParams Then
Dim tp As ThreadParams = DirectCast(parameter, ThreadParams)

'tp.SQL
End If
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim param As New ThreadParams

param.SQL = "hello"

th.Start(param)
End Sub

0

Author Commented:
Hi,
Code doesn't work either.
0

Commented:
What do you mean by doesn't work? Are you getting exceptions? Are you not receiving expected results?
0

Author Commented:
Hi,
Cheers for the post.But what the requirement is
I have a function which is in do loop
Do
Get_SQL_Line(ByRef SQL As String, ByRef reader As IO.StreamReader)
Loop Until (NumLines = LineNo)
Now your first method fails here as I can't start the reader from beginning.
Public Function Get_SQL_Line(ByRef SQL As String, ByRef reader As IO.StreamReader)

Second methods gives error like 'ThreadParams not defined'

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.