Hitmanpt Posted March 30, 2012 at 02:33 PM Report #446608 Posted March 30, 2012 at 02:33 PM Boas Pessoal... o problema é o seguinte.... eu tenho uma form chamada adminCP e uma module com a seguinte estrutura Module updateLists Public Class updatePlayersList Event updateUI '.... O resto do codigo Private Sub updateUI_Handler() Handles Me.updateUI Dim itm As ListViewItem itm = New ListViewItem(id.ToString(), 0) itm.SubItems.Add(Username) itm.SubItems.Add(TeamName) itm.SubItems.Add(Status) If checkIn = 1 Then itm.SubItems.Add("SIM") Else itm.SubItems.Add("NÃO") End If itm.SubItems.Add(firstName) itm.SubItems.Add(lastName) itm.SubItems.Add(email) itm.SubItems.Add(telm) adminCP.Invoke(Sub() adminCP.lstPlayers.Items.Add(itm)) End Sub End Class End Module E na form tenho este codigo Public Class adminCP Dim updatePlayersLST As Thread Private Sub adminCP_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim updatePlayersListClass As updateLists.updatePlayersList = New updateLists.updatePlayersList updatePlayersListClass.MasterAddress = MasterAddress updatePlayersLST = New Thread(AddressOf updatePlayersListClass.updatePlayerslst) updatePlayersLST.Start() End Sub End Class O problema é o seguinte eu estou a utilizar multithreading e para ter o codigo da form mais limpo estou a separar.... visto que o codigo é enorme para estas operações... E quando faz o RaiseEvent e chega a esta linha "adminCP.Invoke(Sub() adminCP.lstPlayers.Items.Add(itm))" dá-me este erro "Não é possível chamar Invoke ou BeginInvoke num controlo até o identificador de janela ser criado." Se tirar o Invoke não me aparece nada na ListView.... alguma ajuda? 😕
Caça Posted March 30, 2012 at 02:38 PM Report #446611 Posted March 30, 2012 at 02:38 PM Chama isso fora do evento load. http://msdn.microsoft.com/pt-br/library/0b1bf3y3.aspx Pedro Martins Não respondo a duvidas por PM
Hitmanpt Posted March 30, 2012 at 08:10 PM Author Report #446707 Posted March 30, 2012 at 08:10 PM Continuo sem conseguir.... meti o codigo que estava no load da form para um botão e msm assim dá o msm erro 😉 EDIT Agora na form para alem do codigo que tinha adicionei este Private Delegate Sub UpdateUIInvoker(ByVal item As ListViewItem) Public Sub UpdateUI(ByVal itm As ListViewItem) If Me.lstPlayers.InvokeRequired Then Dim d As New UpdateUIInvoker(AddressOf UpdateUI) Me.Invoke(d, lstPlayers, {itm}) Else lstPlayers.Items.Add(itm) End If End Sub E na class substitui adminCP.Invoke(Sub() adminCP.lstPlayers.Items.Add(itm)) por adminCP.UpdateUI(itm) agora nao me dá erro... simplesmente nao me aparece nada...
Hitmanpt Posted April 1, 2012 at 05:07 PM Author Report #446913 Posted April 1, 2012 at 05:07 PM Nada?
Hitmanpt Posted April 2, 2012 at 02:38 PM Author Report #447081 Posted April 2, 2012 at 02:38 PM Problema resolvido dps de alguns dias à cabecada :X Na class adiciona-se este codigo Private m_frm As adminCP Public Sub New(ByVal frm As adminCP) m_frm = frm End Sub Na form Dim updatePLList As New updateLists.updatePlayersList(Me) updatePLList.MasterAddress = MasterAddress updatePlayersLST = New Thread(AddressOf updatePLList.updatePlayerslst) updatePlayersLST.Start() e dps é só fazer o Invoke adminCP.lstPlayers.Invoke(Sub() adminCP.lstPlayers.Items.Add(itm))
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now