0

这是我的代码:

    For Each itema In ListBox3.Items
        Dim source As String = getsource(itema)
        If source.Contains("blz blz blz")  Then
            ListBox2.Items.Add(itema & "====> here is one")

        Else
            ListBox2.Items.Add(itema)
        End If

    Next

如何在不等待 vb.net 中所有项目的循环的情况下获得每个项目的结果?在 PHP 中有 flush 和 ob_flush 来刷新内存。

4

2 回答 2

0

如果这是 windows 窗体,您可以使用.Refresh()方法 ( Listbox2.Refresh()),或者如果您使用 windows 窗体,您可以使用.InvalidateVisual()method( Listbox2.InvalidateVisual())

于 2013-04-09T18:33:30.463 回答
0

如果您希望您的项目一项一项添加,则需要“返回”并让它在每个项目之后处理消息泵,以便 WPF 可以更新 UI。

您可以通过将代码拆分为多个 Invoke() 函数来以艰难的方式编写代码,也可以使用 Async/Await。后者看起来像下面的代码。将await Task.Yield()控制权返回给 WPF 消息泵。

Async Sub MyFunction()
    For Each itema In ListBox3.Items
        Dim source As String = getsource(itema)
        If source.Contains("blz blz blz")  Then
            ListBox2.Items.Add(itema & "====> here is one")
        Else
            ListBox2.Items.Add(itema)
        Await Task.Yield()
    End If

Next
于 2017-06-10T07:27:31.320 回答