首页 新闻 搜索 专区 学院

VB.net 跨线程 property 委托 问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-11-13 10:29

有如下代码,请问各位大大,怎么在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
herofire的主页 herofire | 菜鸟二级 | 园豆:306
提问于:2012-11-05 18:49
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册