带参数的线程 [英] Thread with parameters

查看:60
本文介绍了带参数的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



1.在我的代码中,我有一个称为
的方法

Hi,

1. In my code i have a method called

Method1(ByVal Number As String, ByVal ListNumber As String, ByVal created As String, ByVal Value As String, ByVal userId As Integer, ByVal CheckBox As Boolean) As DataTable



2.我正在创建一个线程



2. I am creating a thread

Thread1 = New Threading.Thread(AddressOf Method1)
Thread1.Start()


在这里我遇到了错误,例如Addressof不应包含具有参数的方法.
如何将参数传递给线程.

我们正在使用.net 1.1框架.在这种情况下,我无法实现ParameterizedThreadStart,还有其他实现方式吗?

TIA Subhash.


here i am getting error, like Addressof should not contain a method which has parameters.
How to pass parameters to a thread.

we are using .net 1.1 framework. In this i can''t implement ParameterizedThreadStart, Is there any other way to implement

TIA Subhash.

推荐答案

^ ]应该会为您提供帮助.
This[^] should help you.


NcplThread = New Threading.Thread(AddressOf ThreadWork)
Dim Parameters = new Object(){"1","1.1","User","value",1,True}
NcplThread.Start(Parameters)


Sub ThreadWork(Parameters as Object)
  SearchPickListSource(Parameters(0),Parameters(1),Parameters(2),Parameters(3),   Parameters(4),Parameters(5))
End Sub

Function SearchPickListSource(ByVal soNumber As String, ByVal PickListNumber As String, ByVal createdBy As String, ByVal sxValue As String, ByVal plantId As Integer, ByVal partnerCheckBox As Boolean) As DataTable
...
End Function


查看答案过去的问题:将参数传递给线程化的LongRunningProcess [ ^ ].

我建议使用一个线程包装程序来解决传递参数的问题,VSNetVbHarry为VB.NET实现了该程序.无需参数化线程启动,因为您可以传递通过"Self"的实例(非静态方法).

—SA
See the answers to this past question: Passing arguments to a threaded LongRunningProcess[^].

I suggested a thread wrapper which solves the problem of passing parameters, VSNetVbHarry implemented it for VB.NET. There is not need in parametrized thread start as you can pass an instance (non-static method) which passes "Self".

—SA


这篇关于带参数的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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