If you need idletasks in your loop, and the timer I showed you dosn't work right to show your updates, then I must presume you are not showing us the real code. You might try putting $mw->update; in your loop too, that may help, but it's a bad design.
If you would show us your real code, we probably could show you a better way.