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
RIASAsked:
Who is Participating?
 
käµfm³d 👽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
 
käµfm³d 👽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
    Dim th As New System.Threading.Thread(AddressOf Work)
 
    th.Start()
End Sub
 
Private Sub Work()
    Get_SQL_Line("hello", New System.IO.StreamReader("C:\text.txt"))
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.reader()
        'tp.SQL
    End If
End Function
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim th As New System.Threading.Thread(AddressOf Get_SQL_Line)
    Dim param As New ThreadParams
 
    param.SQL = "hello"
    param.reader = New System.IO.StreamReader("C:\text.txt")
 
    th.Start(param)
End Sub

Open in new window

0
 
RIASAuthor Commented:
Hi,
Code doesn't work either.
0
 
käµfm³d 👽Commented:
What do you mean by doesn't work? Are you getting exceptions? Are you not receiving expected results?
0
 
RIASAuthor 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.