473,608 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The pause that doesn't

I was looking around for some code for a special purpose and found
this. Seems it should print "here we go" , pause 5 seconds, print "now
we are back". Instead, it pauses 5 seconds before printing both lines
with no pause between. Can someone please explain why it behaves that
way. I know in the case of "setTimeout " the only thing affected is the
function, etc. appearing as "setTimeout " arguments. But, this is just
straight code.

<body>
<script language='javas cript'>
document.write( 'here we go<br>');
pausecomp(5000) ;
document.write( 'now we are back');

function pausecomp(Amoun t)
{
d = new Date() //today's date
while (1<2)
{
mill=new Date() // Date Now
diff = mill-d //difference in milliseconds
if( diff > Amount ) {break;}
}
}
</script>

</body>

Jul 23 '05 #1
7 4534
Lee
ar*****@hiwaay. net said:

I was looking around for some code for a special purpose and found
this. Seems it should print "here we go" , pause 5 seconds, print "now
we are back". Instead, it pauses 5 seconds before printing both lines
with no pause between. Can someone please explain why it behaves that
way. I know in the case of "setTimeout " the only thing affected is the
function, etc. appearing as "setTimeout " arguments. But, this is just
straight code.

<body>
<script language='javas cript'>
document.write ('here we go<br>');
pausecomp(5000 );
document.write ('now we are back');

function pausecomp(Amoun t)
{
d = new Date() //today's date
while (1<2)
{
mill=new Date() // Date Now
diff = mill-d //difference in milliseconds
if( diff > Amount ) {break;}
}
}
</script>

</body>

You can't expect the display to be updated by the time the document.write( ) call
returns. That would cause trouble if you wanted to write part of a block in one
call and the rest in a subsequent call, as is not uncommon.

You can't be sure that the document will updated until you invoke
document.close( ), although some browsers will make assumptions about when you're
done.

And you certainly can't expect the browser to update the page when your machine
is wasting 100% of its CPU capacity spinning its wheels waiting for 5 seconds to
pass.

If you want a delay, use setTimeout()

Jul 23 '05 #2
ar*****@hiwaay. net wrote:
I was looking around for some code for a special purpose and found
this. Seems it should print "here we go" , pause 5 seconds, print "now
we are back". Instead, it pauses 5 seconds before printing both lines
with no pause between. Can someone please explain why it behaves that
way. I know in the case of "setTimeout " the only thing affected is the
function, etc. appearing as "setTimeout " arguments. But, this is just
straight code.

<body>
<script language='javas cript'>
document.write( 'here we go<br>');
pausecomp(5000) ;
document.write( 'now we are back');

function pausecomp(Amoun t)
{
d = new Date() //today's date
while (1<2)
{
mill=new Date() // Date Now
diff = mill-d //difference in milliseconds
if( diff > Amount ) {break;}
}
}
</script>

</body>


This is effectively a denial of service attack. It will hog the
CPU by getting it to generate 2 or 3 dates per millisecond (or
maybe 10 or 15 on faster machines than my slow old laptop)
waiting for your script to timeout.

I'm not sure that is what Javascript is for.

--
Fred
Jul 23 '05 #3
Fred Oz wrote:
ar*****@hiwaay. net wrote:
I was looking around for some code for a special purpose and found
this. Seems it should print "here we go" , pause 5 seconds, print "now
we are back". Instead, it pauses 5 seconds before printing both lines
with no pause between. Can someone please explain why it behaves that
way. I know in the case of "setTimeout " the only thing affected is the
function, etc. appearing as "setTimeout " arguments. But, this is just
straight code.

<body>
<script language='javas cript'>
document.write( 'here we go<br>');
pausecomp(5000) ;
document.write( 'now we are back');

function pausecomp(Amoun t)
{
d = new Date() //today's date
while (1<2)
{
mill=new Date() // Date Now
diff = mill-d //difference in milliseconds
if( diff > Amount ) {break;}
}
}
</script>

</body>


This is effectively a denial of service attack. It will hog the
CPU by getting it to generate 2 or 3 dates per millisecond (or
maybe 10 or 15 on faster machines than my slow old laptop)
waiting for your script to timeout.

I'm not sure that is what Javascript is for.

Have a look at "http://www.synchro.net/docs/jsobjs.html" and search for
mswait.

I don't know that there is an inbuilt sleep or wait function in
javascript ( wait for flames !! ) - the secret is to let the CPU do
other things during the sleep period - this may work.
Jul 23 '05 #4
On Sun, 09 Jan 2005 13:30:17 +1100, @(none) <<""mas"@(none) ">> wrote:

[snip]
Have a look at "http://www.synchro.net/docs/jsobjs.html" and search for
mswait.
It's a fairly safe bet that the reference there is specifically for the
Synchronet BBS system. There certainly isn't a mswait function in any
browser object model that I'm aware of.
I don't know that there is an inbuilt sleep or wait function in
javascript
No, there isn't. As both Lee and Fred said, a feature such as that would
cause a browser to hang in most cases as script execution is synchronous.
the secret is to let the CPU do other things during the sleep period -
this may work.


Precisely. Place the to-be-delayed code in a function and use setTimeout
to call it after a certain period of time. However, this couldn't be done
with document.write as the document stream would have closed resulting in
replacement of, rather than addition to, the page.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
>From what I read here I can't do what I want with JS. Using a form
textarea or the status line I can do it.... but, I don't care for
either. I do have a java applet that will work. The application is
very simple. Display a small bit of information followed by a pause
and then display anothr bit of information, pause..... etc. Looping
through an array . Anybody know how to do it?

Jul 23 '05 #6
Lee
ar*****@hiwaay. net said:
From what I read here I can't do what I want with JS. Using a form

textarea or the status line I can do it.... but, I don't care for
either. I do have a java applet that will work. The application is
very simple. Display a small bit of information followed by a pause
and then display anothr bit of information, pause..... etc. Looping
through an array . Anybody know how to do it?


<html>
<head>
<title>demo</title>
<script type="text/javascript">

var info = [
"From what I read here I can't do what I want with JS. Using a form",
"textarea or the status line I can do it.... but, I don't care for",
"either. I do have a java applet that will work. The application is",
"very simple. Display a small bit of information followed by a pause",
"and then display anothr bit of information, pause..... etc. Looping",
"through an array . Anybody know how to do it?"
];

function showInfo() {
info.pos|=0;
document.getEle mentById("canva s").innerHTML=i nfo[info.pos];
info.pos=(info. pos+1)%info.len gth;
info.timer=setT imeout("showInf o()",2000);
}

</script>
</head>
<body onload="showInf o()">
<div id="canvas" style="padding: 1em;background-color:yellow"></div>
</body>
</html>

Jul 23 '05 #7
Thanks Lee !! Nice job.

Jul 23 '05 #8

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

Similar topics

0
1882
by: Andrew | last post by:
When will .NET have a low-pause-time garbage collector A low-pause-time garbage collector would greatly improve .NET's ability to serve as a platform for soft real-time systems. It doesn't have to be perfect. For example, I'd be happy with something where there was at most one pause per second, each pause was less than .2 seconds, and half the process's memory was inaccessible to the application due to garbage collection management It...
11
39874
by: Paminu | last post by:
Is there something like system("PAUSE") for linux?
8
36440
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause seems to work. But I have no clue how to pause/suspend the process. As far as I can see the Process class doesn't offer anything for this. So it's probably the thread the process is running on that should be suspended or put to sleep. But just...
11
1707
by: Marek | last post by:
What can I do in order to avoid first exception pause? I am sure everyone already experienced this behavior and there must be a solution. regards
2
1574
by: allen | last post by:
I'm having a problem in that the first time an exception is thrown in my app, there is about a 2 second pause. After that first time, subsequent exceptions go very quickly. This pause is really annoying the users who think the application is having problems, is there any way I can make it not happen? further, the reason this is happening is that I'm trying to test a class to see if that class implements a certain interface. I'm not...
38
3983
by: Jackie | last post by:
I just want the programme to stop for a while. Thanks.
1
1507
by: OBINT | last post by:
Hi I am using one API to do some process for me, but unfortunately API dont have a option of pause the process and resume it back. How can i do this using C# API take more then 2 hours in processing and takes 100% CPU usage, I want a option so that i can pause the COM to work and resume when required. Thanks in advance.
0
1397
by: Arik | last post by:
Hi, I would like to disable the 'Pause/Break' key in a console application. Normally, pressing the 'Pause' key halts the application's execution and may lead to undesirable processing gaps in my system. I tried to 'listen' for input key presses using Console.ReadKey(), but it turns out that it doesn't recognize the 'Pause' key (among other keys).
2
2047
by: James | last post by:
anyone know why the pause button doesn't work in vb.net 2003? it works on some small applications but not this large one im currently working on. i will appreciate any ideas!
0
8067
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
8501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6820
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2477
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
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1336
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.