Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this one action that takes up a lot of system resources so i want to pass it in a new thread to free up the application whil it runs but the issue i m having is passing the machine name from the textbox into the new thread. i get an error stating it cant find the location and it has no machine name.

so far i have:

VB
Private Sub Radia_Query_Aservice_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Radia_Query_Aservice_Button.Click
    Dim strcomputer As String = Machine_Name_Textbox_Header.Text
    Dim t As New Thread(New ThreadStart(AddressOf radia_data))
    t.Start(strcomputer)

End Sub



if someone can help point me in the direction on how to get the machine into the new thread.
Posted

1 solution

For passing data into thread I recommend using a thread wrapper. It uses the fact that the thread method could be an instance method (non-static) and hence pass "this" to the thread, but to be effective, the instance of the type passes should be some class wrapping the thread object. It also provides nice encapsulation and abstraction of thread synchronization.

For more detail, please see my past answers where I explain this technique:
How to pass ref parameter to the thread[^],
change paramters of thread (producer) after it started[^].

This is a nice translation to VB.NET by VSNetVbHarry:
Passing arguments to a threaded LongRunningProcess[^].

For better understanding of how instance methods work (in case you need it, of course), please see my other answer:
What makes static methods accessible?[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900