How to let the code run smoothly using timers and different threads

后端 未结 2 1631
暖寄归人
暖寄归人 2021-01-29 05:12

I\'m trying to prevent the GUI from freezing, because of a low timer interval and too much to process in the Timer.Tick event handler.
I\'ve been goo

2条回答
  •  长情又很酷
    2021-01-29 05:52

    Your listbox and richtextbox accesses must run on the UI thread. The easiest way to do it is like this.

                                         Me.Invoke(Sub()
                                                       ListBox1.Items.Clear()
                                                       ListBox1.Items.AddRange(Split(clientdecode, vbLf))
                                                       RichTextBox1.SelectionStart() = RichTextBox1.TextLength
                                                       RichTextBox1.ScrollToCaret()
                                                   End Sub)
    

提交回复
热议问题