Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-23
5
Medium Priority
?
786 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:RIAS
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24215408
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
 

Author Comment

by:RIAS
ID: 24215555
Hi,
Code doesn't work either.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24216179
What do you mean by doesn't work? Are you getting exceptions? Are you not receiving expected results?
0
 

Author Comment

by:RIAS
ID: 24216421
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
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 750 total points
ID: 24216593
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Screencast - Getting to Know the Pipeline

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question