Martin
Martin

Reputation: 24308

Having to use DelayedTask otherwise LoadMask doesn't show

I am doing a few processes that take time so I want to be able to show a mask, I use LoadMask. Problem is that the code that I want to run seems to run too quick and I presume is blocking the UI to show the mask. The process takes around 4 seconds so I know the mask isn't being enabled and disabled at the same time.

The way I got around this was to use a delayed task, but it kind of feels like a code smell.

Can I do this a different way?

Here is what I have

    var myMask = new Ext.LoadMask(win, {});
    myMask.show();

    var task = new Ext.util.DelayedTask(function () {

         ....... // DO MY stuff and eventually do a myMask.hide()

    task.delay(400);

It works great but I was wondering if this is the right way to go ?

If I remove the delayedtaks then the mask never seems to display, but the process does work.

Upvotes: 0

Views: 416

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30082

Assuming your "process" is some kind of local sequential procedure, what you said above is pretty much correct. If your code is running a busy loop it won't relinquish control to the UI "thread" for the browser to redraw.

So you won't see the mask here;

mask();
busyLoop();
unmask();

But if you do:

mask();
setTimeout(function() {
    busyLoop();
    unmask();
}, 1);

It gives the browser time to draw before you get into your stuff.

Upvotes: 2

Related Questions