Torna al Thread

Private Lista_dati As New Threading.Thread(AddressOf caricagriglia) Private Sub Iva_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown Lista_dati.Start() End Sub Private Sub caricagriglia() Me.ListView1.BeginUpdate() Me.ListView1.Clear() Me.Label5.Visible = True My.Application.DoEvents() '-----carimento elenco dati SqlCmd.CommandText = "Select * From Tab_Iva Order By id" SqlCmd.Connection = Db SqlCmd.CommandType = CommandType.Text SqlDr = SqlCmd.ExecuteReader While SqlDr.Read litem = ListView1.Items.Add(SqlDr.GetSqlInt32(0).Value) Sublist = litem.SubItems.Add(SqlDr.GetSqlString(1).Value) Sublist = litem.SubItems.Add(SqlDr.GetSqlString(2).Value) End While Me.ListView1.EndUpdate() SqlDr.Close() SqlCmd.Dispose() '-------------------------- My.Application.DoEvents() Me.Label5.Visible = False End Sub ed è uscit il seguente errore: Cross-thread operation not valid: Control 'ListView1' accessed from a thread other than the thread it was created on.
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5