線程結(jié)束后利用委托生成事件返回,線程應(yīng)用包括傳銀和叢入鋒櫻和傳出棚液參數(shù)。
創(chuàng)新互聯(lián)主營(yíng)敘永網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開(kāi)發(fā),敘永h5微信小程序定制開(kāi)發(fā)搭建,敘永網(wǎng)站營(yíng)銷(xiāo)推廣歡迎敘永等地區(qū)企業(yè)咨詢(xún)
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 = "測(cè)試"
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
新窗體中寫(xiě)
構(gòu)造函數(shù)
,然后調(diào)用。
比如你要調(diào)用的新窗體手耐是From1.cs這個(gè)窗體,
public
Form1(要傳入的參數(shù))
{
//把傳入的參數(shù)者枯傳入窗體中畢嫌春
//執(zhí)行窗體標(biāo)準(zhǔn)內(nèi)容
}
然后在需要調(diào)用的地方調(diào)用
Form1
f
=
new
Form1(傳出的參數(shù));
'--------Form1--------
Dim
f2
As
Form2
Private
Sub
Command1_Click()
Set
f2
=
New
Form2
f2.Show
vbModal
End
Sub
'--------Form1
End--------
'--------Form2--------
Dim
WithEvents
f3
As
Form3
Private
Sub
Command1_Click()
Set
f3
=
New
Form3
f3.Show
End
Sub
Public
Sub
f3_f2W()
Me.Command1.Caption
=
"f2W"
End
Sub
'--------Form2
End--------
'--------Form3--------
Public
Event
f2W()
Private
Sub
Command1_Click()
RaiseEvent
f2W
End
Sub
'--------Form3
End--------
f.Show();
如此就能實(shí)現(xiàn)調(diào)用了。
1.對(duì)象變量與對(duì)象本身是不同的,對(duì)象變量代表了對(duì)象真實(shí)數(shù)據(jù)在內(nèi)存中的地址仿悄明.
打個(gè)比方,“對(duì)運(yùn)圓象變量”就象你家的地址,“對(duì)象本身”就象你家。
你不能說(shuō)你家的地址(xx路xx號(hào)xx房)就是你家,但是可以通過(guò)這個(gè)地址而找到你家。
2.傳值的參數(shù)本身是被復(fù)制一份的,但這并不意味著它所代表的對(duì)象也被復(fù)制一份.
有如下一個(gè)函數(shù):
Public
Function
Do_delete(ByVal
ps_usr_id
As
String)
As
Boolean
你在調(diào)用時(shí)可能這樣調(diào)用:
dim
strID
as
string
strID
=
"kknd001"備告
if
Do_delete(strID)
then.....
當(dāng)程序執(zhí)行到Do_delete函數(shù)體里面時(shí)ps_usr_id變量其實(shí)是按照StrID的值而復(fù)制的一個(gè)變量。