vb.net线程参数 vb多线程实例

Vb.net 怎样操作有参数的多线程而且还是循环的。

Sub Main()

站在用户的角度思考问题,与客户深入沟通,找到隆阳网站设计与隆阳网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、网站制作、企业官网、英文网站、手机端网站、网站推广、空间域名、虚拟空间、企业邮箱。业务覆盖隆阳地区。

Dim thr As New Thread(AddressOf 循环)

thr.Start("a")

End Sub

Sub 循环(a() As String)

'这里随你干什么循环也行

For Each i As String In a

MsgBox(i)

Next

End Sub

看懂了吧 参数只能有一个 也可以不是数组,在a() As String的a后面去掉括号就行

vb.net 如何传递类参数

线程结束后利用委托生成事件返回,线程应用包括传入和传出参数。

Public Delegate Sub ThreadCallback(value As ThreadResult)

Public Class Form1

Private WithEvents _th_1 As Thread_1

Protected Overrides Sub OnLoad(e As System.EventArgs)

Dim value As ThreadObject

value.Index = 1

Me._th_1 = New Thread_1(Me)

Me._th_1.Run(value)

MyBase.OnLoad(e)

End Sub

Private Sub Thread_1_End(sender As Object, e As ThreadEventArgs) Handles _th_1.ThreadEnd

Me.TextBox1.Text = e.Result.Text

End Sub

End Class

Public Class Thread_1

Public Event ThreadEnd(sender As Object, e As ThreadEventArgs)

Private _control As Control

Sub New(control As Control)

Me._control = control

End Sub

Public Sub Run(value As Object)

Dim th As New Threading.Thread(AddressOf ThreadProc)

th.Start(value)

End Sub

Private Sub ThreadProc(obj As Object)

Dim value As ThreadObject = CType(obj, ThreadObject)

Dim result As ThreadResult = Nothing

If value.Index = 1 Then result.Text = "测试"

Dim callback As New ThreadCallback(AddressOf ThreadInvoke)

_control.Invoke(callback, result)

End Sub

Private Sub ThreadInvoke(value As ThreadResult)

RaiseEvent ThreadEnd(Me, New ThreadEventArgs(value))

End Sub

End Class

Public Structure ThreadObject

Public Index As Integer

'Public Rect As Rectangle

End Structure

Public Structure ThreadResult

Public Text As String

'Public Rect As Rectangle

End Structure

Public Class ThreadEventArgs

Inherits System.EventArgs

Private _result As ThreadResult

Public ReadOnly Property Result As ThreadResult

Get

Return _result

End Get

End Property

Sub New(value As ThreadResult)

Me._result = value

End Sub

End Class

vb.net多线程如何返回参数,举个例子,谢谢

Public Class Form1

Public Class SquareClass '把多线程调用的函数封装到类中,通过类事件返回

Public Value As Double

Public Square As Double

Public Event ThreadComplete(ByVal Square As Double)

Public Sub CalcSquare()

Square = Value * Value

RaiseEvent ThreadComplete(Square)

End Sub

End Class

Dim WithEvents oSquare As SquareClass

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '多线程返回值测试,当线程运行完成激发事件

oSquare = New SquareClass()

Dim t As New Threading.Thread(AddressOf oSquare.CalcSquare)

oSquare.Value = 30

t.Start()

End Sub

Sub SquareEventHandler(ByVal Square As Double) Handles oSquare.ThreadComplete '响应事件函数

MsgBox("The square is "  Square)

End Sub

End Class

VB.NET线程内调用带参数的方法异常

报错信息是什么?截图一下。

---------补充----------------

你这报错与线程应该关系不大吧,是调用COM不熟悉造成的,在项目属性里面有些相关配置你研究研究。


网页名称:vb.net线程参数 vb多线程实例
URL标题:http://csdahua.cn/article/dojojpc.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流