Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
net Framework 2.0(VB.net)中的多线程填充listview_Vb.net_Multithreading_Listview - Fatal编程技术网

net Framework 2.0(VB.net)中的多线程填充listview

net Framework 2.0(VB.net)中的多线程填充listview,vb.net,multithreading,listview,Vb.net,Multithreading,Listview,我是vbnet中多线程的新手。我犯了这个错误 跨线程操作无效:从非 创建它的线程。 这是我的密码 Private Sub xFormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim t As Threading.Thread t = New Threading.Thread(AddressOf populateLV) t.Start() End

我是vbnet中多线程的新手。我犯了这个错误

跨线程操作无效:从非 创建它的线程。

这是我的密码

Private Sub xFormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim t As Threading.Thread
    t = New Threading.Thread(AddressOf populateLV)
    t.Start()
End Sub

Private Sub populateLV()

    Dim a As Integer = 0
    With lvSample
        a = .Width
        .View = View.Details
        .Columns.Add("Item", CInt(a * 0.33), HorizontalAlignment.Left)
        .Columns.Add("S-Item1", CInt(a * 0.33), HorizontalAlignment.Left)
        .Columns.Add("S-Item2", CInt(a * 0.33), HorizontalAlignment.Left)

        Dim iLv(99) As ListViewItem
        For b As Integer = 0 To iLv.GetUpperBound(0)
            iLv(b) = .Items.Add("Item-" & b.ToString("00"))
            iLv(b).SubItems.Add("SubItem(1)-" & b.ToString("00"))
            iLv(b).SubItems.Add("SubItem(2)-" & b.ToString("00"))
        Next
    End With

    lvSample.Items(99).Selected = True
    lvSample.Items(99).EnsureVisible()

End Sub

我该怎么办?

在代码中添加这一行(如果需要,可以在form\u load函数中)


这将允许其他线程修改当前线程的对象。UI元素只能从UI线程访问。因此,不要从工作线程更新UI,而是使用这些方法在UI线程中发送更新调用(
lvSample.BeginInvoke

更多细节在这里

  • )

  • 我已经尝试过该代码,但这是一个大型系统,我知道如果添加该代码,调试会很困难
    System.Windows.Forms.ThreadExceptionDialog.CheckForIllegalCrossThreadCalls = false