读书人

多线程操作窗体控件的有关问题

发布时间: 2012-08-11 20:50:31 作者: rapoo

多线程操作窗体控件的问题!
Private Delegate Sub SetUserList(ByVal Index As Integer, ByVal subItemIndex As Integer, ByVal str As String)

Private OnLine As New SetUserList(AddressOf SetUserListItem)


Public Sub SetUserListItem(ByVal itemIndex As Integer, ByVal subItemIndex As Integer, ByVal str As String)

Dim obj(2) As Object

obj(0) = itemIndex

obj(1) = subItemIndex

obj(2) = str

If frm_Server.lst_User.InvokeRequired Then

frm_Server.lst_User.Invoke(OnLine, obj)

Else

frm_Server.lst_User.Items(itemIndex).SubItems(subItemIndex).Text = str

End If

End Sub

把线程函数写在窗口类中调用这个委托就可以实现修改,把线程函数写在模块中,再调用此委托的时候frm_Server.lst_User.InvokeRequired 这个值一直返回FALSE,不知道怎么解决

[解决办法]
我也遇到过,但没仔细研究具体原因,只是把delegate部分放在了同一个类中(此处即窗口类)

读书人网 >VB Dotnet

热点推荐