473,704 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Window repaint/redraw delay

I have some code like:

try {
someButton.disa bled = true;
cpuIntensiveCod e();
} finally {
someButton.disa bled = false;
}

The problem is that someButton is never disabled, because the browser
is busy thinking in cpuIntensiveCod e. Indeed, if I don't reenable
someButton in the finally part, it waits until cpuIntensiveCod e is over
to disable someButton.

The only way to disable someButton before cpuIntensiveCod e is to force
the browser to redraw the window (eg: by putting an alert(...) just
after someButton is disabled).

I don't want a useless alert popping every time I run cpuIntensiveCod e.
Does someone know a way to force the redraw of the browser window (not
reloading the page, just redrawing it)?

Apr 19 '06 #1
2 13071
di*****@gmail.c om said the following on 4/19/2006 3:32 PM:
I have some code like:

try {
someButton.disa bled = true;
cpuIntensiveCod e();
} finally {
someButton.disa bled = false;
}
As long as you know the drawbacks and problems with try/catch/finally.
The problem is that someButton is never disabled, because the browser
is busy thinking in cpuIntensiveCod e.
It is disabled, it just hasn't changed view on the browser window.
Indeed, if I don't reenable someButton in the finally part, it waits
until cpuIntensiveCod e is over to disable someButton.
No, it waits until it is completed to continue execution at which time
it would show the disabled button even though the button was disabled to
start with.

The only way to disable someButton before cpuIntensiveCod e is to force
the browser to redraw the window (eg: by putting an alert(...) just
after someButton is disabled).
Read above. Use a settimeout and you will see the difference:

try {
someButton.disa bled = true;
window.setTimeo ut(cpuIntensive Code,100);
} finally {
someButton.disa bled = false;
}

But, why are you even using try/finally there?
I don't want a useless alert popping every time I run cpuIntensiveCod e.
Then don't use one.
Does someone know a way to force the redraw of the browser window (not
reloading the page, just redrawing it)?


See above.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 19 '06 #2
On 2006-04-19 22:35:44 +0200, Randy Webb <Hi************ @aol.com> said:
di*****@gmail.c om said the following on 4/19/2006 3:32 PM:
I have some code like:

try {
someButton.disa bled = true;
cpuIntensiveCod e();
} finally {
someButton.disa bled = false;
} The problem is that someButton is never disabled, because the browser
is busy thinking in cpuIntensiveCod e.


It is disabled, it just hasn't changed view on the browser window.


actually, it is not disabled, but neither will the browser acknowledge
any user activity while the code is running. It may remember any clicks
and later call any callback methods that should have been called, of
forget them.
Indeed, if I don't reenable someButton in the finally part, it waits
until cpuIntensiveCod e is over to disable someButton.


No, it waits until it is completed to continue execution at which time
it would show the disabled button even though the button was disabled
to start with.


Actually, it seems the behavior of interface elements is not updated
much sooner than their graphical display. If a button is showed as
disabled you cannot click it, even if you just fired some code which
enables it but that code is not completed. That may depend on browsers
though. I can't test with IE.
The only way to disable someButton before cpuIntensiveCod e is to force
the browser to redraw the window (eg: by putting an alert(...) just
after someButton is disabled).


Read above. Use a settimeout and you will see the difference:

try {
someButton.disa bled = true;
window.setTimeo ut(cpuIntensive Code,100);
} finally {
someButton.disa bled = false;
}


Browsers don't update the display while the code that initiated the
updates is still running.

so, setTimeout is indeed the way to go, because it creates a sort of
"thread" that may execute very quickly and as soon as it's done, the
browser will redraw whatever was affected by that thread.

But the above example won't work as intended. The "CPU intensive code"
will be executed in a separate thread, completely outside of the try()
statement. So, yes, the button will be disabled immediately, but it
will also be re-enabled after 100ms, whether the CPU intensive code is
completed or not (only the setTimeout call must be completed, which
shouldn't take too long).

What you should do is the opposite :

try {
window.setTimeo ut("someButton. disabled = true", 1)
cpuIntensiveCod e
} finally {
someButton.disa bled = false
}

What this code does is detach a small thread that will execute almost
immediately (you may not want to rely on the button being unable to
intercept another onclick event, since many things can happen during
one millisecond) and change a property of the button. Since that thread
will be completed, the browser will redraw the button and handle user
events accordingly.
Meanwhile, the main thread will compute your intensive code, and won't
re-enable the button until that code is finished, since the re-enabling
code is part of the same thread.

Apr 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
561
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
1
2321
by: John | last post by:
How to draw anmation in window app? I mean... like how can I draw a dot in window at a point then moves to another point and we can see it moves. Please explain in detail.
0
1185
by: Víctor | last post by:
Hello, I'm doing a Intranet application which shows some information panels dinamically. Each panel is a dll loaded dinamically using Reflection and inherits from Panel class. To display information, I use controls inheriteds from ListView with updated styles (this.SetStyle(ControlStyles.ContainerControl | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint |...
1
3130
by: Diogo Alves - Software Developer | last post by:
Hi there, Since my last questions wasn't very clear, I will do it in a different way. I want to resize my app but while resizing I dont want to see content of the form, I just want to see the window border, then on release, the form reappears, just like when we use "Show window contents while dragging" on the windowsXP appearance settings... Any Ideas in how to do it?
4
1923
by: astromac | last post by:
I'm new to php and was wondering if the following was possible... I would like to have a list of items loaded from a text file, process each item in the list and then return the processed result to a new window so that the new window displays the results, one by one, until it is done processing the list. I considered javascript but the whole client-side/server-side divide seems difficult for this newbie to figure out. Is what I want...
2
5045
by: Tony | last post by:
Hi, In a form, when I change the LitterLine field, I programmatically update the PupLine field, (as in the sample code below). However, the PupLine field only gets updated the first time after the form is opened. After that, if I keep the form opened and change LitterLine a second time to something else, Pupline does get updated but not repainted. When I move the form off screen and back, it gets repainted. I tried Me.Repaint, but it...
7
5000
by: Paul | last post by:
I have a VB.NET form with a DataGrid. When I toggle to Excel (for example) and then back to my application the repaint of the DataGrid is really slow. You can see the repainting happening. When I toggle back to Excel, it does not do that. The repaint is quick. I'm running this within a Citrix environment. The scrolling of the DataGrid is slow also. Would anyone know how I can fix or even determine what is going on? Thank you!
3
18199
by: linuxadmin | last post by:
hello! i want to be able to repaint a class, derived from a form, by myself. it works automatically, when i do: protected override void OnPaint(PaintEventArgs e){ base.OnPaint(e); Graphics g=e.Graphics; // draw something
0
8766
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9134
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9025
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4438
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3134
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.