用vb.net将计算机名称传递到新线程 [英] passing machine name to a new thread with vb.net

查看:77
本文介绍了用vb.net将计算机名称传递到新线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要占用大量系统资源的操作,因此我想将其传递到新线程中以释放运行时的应用程序,但问题是我将机器名从文本框中传递到了新的应用程序中线.我收到一条错误消息,指出它找不到该位置,并且它没有计算机名称.

到目前为止,我有:

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:

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.

推荐答案

要将数据传递到线程中,建议使用线程包装器.它使用以下事实:线程方法可以是实例方法(非静态),因此可以将"this"传递给线程,但要有效,类型传递的实例应该是包装线程对象的某个类.它还提供了很好的线程同步封装和抽象.

有关更多详细信息,请参阅我过去的答案以解释该技术:
如何将ref参数传递给线程 [ ^ ],
启动后更改线程(生产者)的参数 [ ^ ].

这是VSNetVbHarry对VB.NET的很好翻译:
将参数传递给线程化的LongRunningProcess [什么使静态方法可访问? [
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


这篇关于用vb.net将计算机名称传递到新线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆