Yes, and not just this. Never use
DoEvents
for such purposes. Always use a separate thread for anything which has it's own linear or circular logic, and for anything which contains blocking calls or contain lengthy operation. Even though
DoEvents
can work as a quick and dirty UI thread based work-around, it's not so quick but is too dirty for many cases to work correctly.
If you use a non-UI thread with UI applications, you need to understand that you cannot call any UI methods or properties directly from such thread, you need to use invocation mechanism I describe in detail in my past answers. Please see:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
Please also see more references on threading based on my past answers:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
—SA