Hi!
I have a problem with an object not yet being initialized when I try to
access it. Hence I would like to wait for the object to be initialized. I
have the following code:
try
{
if(gridArray == null)
{
setTimeout("wai tForGridArray() ", 500);
}
for (var i = 0; i < gridArray.lengt h; ++i)
.....
}
}
catch(e)
{
alert(e.message );
}
function waitForGridArra y()
{
if(gridArray == null)
{
setTimeout("wai tForGridArray() ", 500);
alert("Waiting) ;
}
}
The problem is that even though I want to wait I get an "gridArray.leng th is
null or not an object" error, followed by the "Waiting" alert.
Why doesn't it wait until gridArray is ready and the continue? (Windows
Server 2003)
Best regards
Hansen 5 4429
Hansen wrote: Hi!
I have a problem with an object not yet being initialized when I try to access it. Hence I would like to wait for the object to be initialized. I have the following code:
Please indent code, preferably using 2 or 4 spaces:
try { if(gridArray == null) { setTimeout("wai tForGridArray() ", 500); }
The whole try..catch block is in a global scope and will be executed as
the script engine comes across it. Therefore after doing the 'if'
statement, whatever the result, it will continue to the following 'for'
statement. Put the try..catch inside a function and put a return inside
the 'if' block to stop execution.
for (var i = 0; i < gridArray.lengt h; ++i)
{ // I guess there was an opening brace here?
.... } }
catch(e) { alert(e.message ); }
function waitForGridArra y() { if(gridArray == null) { setTimeout("wai tForGridArray() ", 500); alert("Waiting) ;
Put a return here.
}
And call the function you want to execute here.
}
The problem is that even though I want to wait I get an "gridArray.leng th is null or not an object" error, followed by the "Waiting" alert. Why doesn't it wait until gridArray is ready and the continue? (Windows Server 2003)
Because you continue with the code regardless of what the if block
returns. The following is a pattern that may work, however there is
likely a better way if you explain a little more about what you are
trying to do:
function doSomethingToGr idArray()
{
/* ... */
}
function waitForGridArra y()
{
if (typeof gridArray == 'undefined'){
setTimeout('wai tForGridArray() ;', 500);
return;
}
doSomethingToGr idArray();
}
waitForGridArra y();
--
Rob
> Please indent code, preferably using 2 or 4 spaces:
Sorry - will do.
I made a small error not displaying the check as being inside a function. So
here is the actual code, with a few modifications.
function makeHTML()
{
try
{
if(gridArray == null)
{
waitForGridArra y();
}
for (var i = 0; i < gridArray.lengt h; ++i)
{
.... <do stuff>
}
}
catch(e)
{
alert(e.message );
}
}
function waitForGridArra y()
{
if(gridArray == null)
{
setTimeout("wai tForGridArray() ", 500);
alert("Waiting) ;
}
else
{
return;
}
}
It seemed as if the setTimeout("wai tForGridArray() ", 500); I had in my if()
check, allowed the execution to continue, rendering the gridArray.lengt h =
null error.
It seems that I have misunderstud the use of setTimeout().
What I'm trying to do is to use it as a sleep, but the way I havde descriped
here, allows for futher execution, which causes the gridArray error.
I'm only saved by the alert() since it halts execution. But the alert is for
testing purpose so I need to find another solution.
How do I make a "sleep" that doesn't continue, until the gridArray object
exists? function makeHTML() { try { if(gridArray == null) { waitForGridArra y(); } for (var i = 0; i < gridArray.lengt h; ++i) { .... <do stuff> } } catch(e) { alert(e.message ); } }
function waitForGridArra y() { if(gridArray == null) { setTimeout("wai tForGridArray() ", 500); //Execution continues for another 500 ms. alert("Waiting) ; //Saves me, since othervise I would have returned and accessed the gridArray object } else { return; } }
Hansen wrote: It seems that I have misunderstud the use of setTimeout(). What I'm trying to do is to use it as a sleep, but the way I havde descriped here, allows for futher execution, which causes the gridArray error. I'm only saved by the alert() since it halts execution. But the alert is for testing purpose so I need to find another solution.
How do I make a "sleep" that doesn't continue, until the gridArray object exists?
You can't, which is why I suggested having a 'wait' function that uses
setTimeout to call itself. When gridArray becomes available, then it
calls another function. You should not be using try..catch at all for this.
--
Rob
"RobG" <rg***@iinet.ne t.au> wrote in message
news:44******** **************@ per-qv1-newsreader-01.iinet.net.au ... Hansen wrote: It seems that I have misunderstud the use of setTimeout(). What I'm trying to do is to use it as a sleep, but the way I havde descriped here, allows for futher execution, which causes the gridArray error. I'm only saved by the alert() since it halts execution. But the alert is for testing purpose so I need to find another solution.
How do I make a "sleep" that doesn't continue, until the gridArray object exists?
You can't, which is why I suggested having a 'wait' function that uses setTimeout to call itself. When gridArray becomes available, then it calls another function. You should not be using try..catch at all for this.
Thanks for the help. As you suggested, I've made a function which calls
itself until gridArray is ready, and then it calls makeHTML();
/Hansen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Burns |
last post by:
Hi,
I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try to recieve, no response has returned. I'm assuming that this is because the server hasn't had the chance to respond before the recieve buffer is read. If this is the case, then how do I tell my code to wait around before checking the stream?
If I just have a do{}until loop constantly...
|
by: gerry |
last post by:
I have a com object that is used via an interop assembly - ie. I referenced
the com object and vs.net created the interop .dll for it.
I create one object per session when the page 1st loads and store it in the
Session. I expected that the object would be released when the Session
object was destroyed during at Session_End(). In my log I can see the
Session_End() event firing as it should after the specified idle time,
however the actual...
|
by: Anson |
last post by:
Hello,
I would like to clarify something about Remoting Object in .NET.
Knowing from MSDN that in order for Remote Object to work, I need 3
components.
a) RemotableType object, just like a regular dll with additional remotable
feature.
b) Host Application, which is a listener listens for remote clients of a
remotable type
|
by: Raymond Lewallen |
last post by:
How to wait for a process to stop completion is my goal. Obviously, the
looping while waiting for the HasExited property is not a solution.. but
thats the best I can come up off the top of my head. Natuarally it will not
work. I expect it to use up all resources looping, which will not allow the
process to complete. The process takes about 60 seconds, because the .bat
file it is calling is rebuilding mulitple .NET solutions and projects...
|
by: Bruce Wood |
last post by:
Maybe it's just late in my day, but I'm reading Jon's article on
threading, in particular how to use Monitor.Wait() and Monitor.Pulse(),
and there's something that's not sinking in. The code in question
looks like this:
public class ProducerConsumer
{
readonly object listLock = new object();
Queue queue = new Queue();
| |
by: Bob |
last post by:
I launch Word from within my application (Vs2005, VB) and I would like to
make it necessary for the just opened Word to be closed before the rest of
my code in the calling sub can execute. How can I do this?
Thanks for any help
Bob
|
by: =?Utf-8?B?QmlsbEI=?= |
last post by:
This is a tough one...
My Windows Service app periodically performs some processing on new entries
to a SQL Server database table. It uses a simple System.Timer to call the
Elapsed event handler (which contains the processing code) every minute. The
processing itself usually takes no more than a few seconds. Even so, I have
a boolean set in the event handler when I'm currently processing information
so that only one thread is...
|
by: Simon_21 |
last post by:
Hi All,
I have a servlet which is invoked from a jsp page. While the serlvet
is executing, the jsp page is waiting for the servlet to complete.
When the servlet completes, it informs the waiting jsp to redirect to
another page. The waiting jsp has implemented onload which will
redirect to the page informed by the servlet
Server : (tomcat 6.0), Browser - IE 6.0, OS - WinXP
|
by: Sarah |
last post by:
Hi -
Please be gentle. I am quite new to visual basic, but I have been
going through tutorials and reading up. I found a code snippet on the
internet that I wanted to see if I could re-purpose for a project, but
I keep getting the error: "Object reference not set to an instance of
an object" for the 7th line of the code below which is:
obj.ConvertPage(URL).Save("C:\screencaptest2.bmp",
System.Drawing.Imaging.ImageFormat.Bmp)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |