
正文
vb.net跨线程传值 c# 跨线程调用窗体
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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
相关问答
Q1: vb.net 窗体之间怎么传值
方法很多,vb.net很简单的比如: Form2窗体的Textbox2属性设置为public,在Form1点击button1.
Dim frm As New Form2
frm.TextBox2.Text = "123"
frm.ShowDialog() 可以取到form1里面窗体传的值
还有一种方法:From1 :
Dim frm As New Form2
frm.Owner = Me
frm.ShowDialog()
from2 : Private frmParent As Form1
frmParent = Me.Owner
Me.TextBox2.Text = frmParent.TextBox1.Text
Q2: VB.NET Public Sub 窗体 互相传值
Public Sub checkInjectionWithNoKeyword()
Dim injection_Type As String = My.Forms.SqlInjection.ComboBox_Type.Text.Trim()
Dim my_checkUrl As String = My.Forms.SqlInjection.ComboBox_Url.Text.Trim()
end sub
这个改成放在窗体内就行了,我也有遇到同样的问题,最后只好放窗体里才能实现。
网上找的什么委托都是不行的。
Q3: VB.NET跨线程操作控件
最简单的方法是
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False'加入这句代码就可以在别的线程访问窗体控件了
End Sub
关于vb.net跨线程传值和c# 跨线程调用窗体的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








