有如下代码,请问各位大大,怎么在EndIdentify里获得uid及设置uid的值?
1 Public Class Form 2 Private uid As String '当前用户 3 Public Property CurrUid() As String 4 Get 5 Return uid 6 End Get 7 Set(ByVal value As String) 8 uid = value 9 End Set 10 End Property 11 12 Public Sub New() 13 InitializeComponent() 14 Identify() 15 End Sub 16 17 Private Sub Identify() 18 Dim threadIdentify As Identify 19 threadIdentify = New Identify(Me) 20 End Sub 21 Public Sub EndIdentify() 22 请问这里怎么获得uid的值,并设置uid的值? 23 End Sub 24 25 End Class 26 Public Class Identify 27 Private mainForm As Form 28 Public Sub New(ByVal form As Form) 29 mainForm = form 30 Dim td As New Thread(AddressOf IdentifyStart) 31 td.Start() 32 End Sub 33 Private Sub IdentifyStart() 34 mainForm.EndIdentify() 35 End Sub 36 End Class
'尝试采用 委托 方式实现,但是第2次执行EndIdentify时,仍然无法获得第1次执行EndIdentify时设置的uid值。代码如下。
Public Class Form Private uid As String '当前用户 'property Public Property CurrUid() As String Get Return uid End Get Set(ByVal value As String) uid = value End Set End Property '声明委托 Public Delegate Function StringPropertyDg(ByVal s As String) As String '试图通过这个方法来获得和设置uid Public Function StringPropertyGatter(ByVal s As String) As String If(s<>"") Then uid = s End If Return uid End Function Public Sub New() InitializeComponent() Identify() End Sub Private Sub Identify() Dim threadIdentify As Identify threadIdentify = New Identify(Me) End Sub Public Sub EndIdentify() '实例化委托 Dim d As New StringPropertyDg(AddressOf StringPropertyGatter) MsgBox(d.Invoke("")) '获取uid的值,每次执行EndIdentify都是空的,何解? id.Invoke("123456")'设置uid的值 End Sub End Class Public Class Identify Private mainForm As Form Public Sub New(ByVal form As Form) mainForm = form Dim td As New Thread(AddressOf IdentifyStart) td.Start() End Sub Private Sub IdentifyStart() mainForm.EndIdentify() End Sub End Class