VB,Net, fast updating on textbox

PNRT
PNRT used Ask the Experts™
on
Hi Experts
VB.Net 4
I have a queue to which I am adding +- 5000 strings on a separate thread
To Speed things up, while these strings are being added, I am taking the strings from the queue and adding them to a textbox, fired from a timer on the main thread.

If I use -
        If SelectedFilesQueue.Count <> 0 Then
            TextBox1.AppendText(SelectedFilesQueue.Dequeue.ToString & vbCrLf)
        End if
It works well but is VERY slow to complete

If I use -
          While SelectedFilesQueue.Count <> 0
            TextBox1.AppendText(SelectedFilesQueue.Dequeue.ToString & vbCrLf)
        End While
This is fast, takes a quarter of the time, but it freezes my GUI.

If I try and add the second example to a separate thread,  I still have the problem of updating the GUI from that thread
Anyone know how to keep the speed but stop the GUI from freezing?
Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance programmer / Consultant
Commented:
This might need a little modification but you can add the DoEvents which tells the application to perform any pending GUI work before continuing.

While SelectedFilesQueue.Count <> 0
            TextBox1.AppendText(SelectedFilesQueue.Dequeue.ToString & vbCrLf)
Application.DoEvents
        End While
AndyAinscowFreelance programmer / Consultant

Commented:
In VB apparently it need the brackets
Application.DoEvents()

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial