473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

timer problem

Hi,

I have timer class and some classes use timer.
but when i come back from timer with callback function, i can see this. properties.

Expand|Select|Wrap|Line Numbers
  1. function Timer(dName, dCallback){
  2.     this.timer = null;
  3.     this.name = dName;
  4.     this.isRunning = false;
  5.     this.interval = 50;
  6.     this.callback = dCallback;
  7. }
  8.  
  9. Timer.prototype.Start = function()
  10. {
  11.     this.timer = self.setTimeout(this.callback,this.interval);
  12.     this.isRunning = true;
  13. }
Expand|Select|Wrap|Line Numbers
  1. var timer;
  2. function File(path) 
  3. {
  4.     ....
  5.     if (timer == null) 
  6.         timer = new Timer("load",File.prototype.WaitForUnFinishedFiles);
  7.     ....
  8. }
  9.  
  10. File.prototype.WaitForUnFinishedFiles = function()
  11. {
  12.     var isAllFinished = true;
  13.     for(eFile in cache)
  14.     {
  15.         if(!cache[eFile].isReady)
  16.         {
  17.             isAllFinished = false;
  18.             break;
  19.         }
  20.     }
  21.     debugtext("load :::" + this.fileName);
  22.     if(!isAllFinished)
  23.         timer.Start();
  24. }
and i call it in main.js

Expand|Select|Wrap|Line Numbers
  1.  
  2.         file = new File("http://bytes.com/images/simon_00.png");
  3.     file.WaitForUnFinishedF();
i used debugtext just for testing something but it says undefined. and its important for me to see this. properties after coming back from timer.

thanks
Aug 14 '09 #1
7 2273
Dormilich
8,658 Expert Mod 8TB
@genesistr
this method is indeed not defined. try file.WaitForUnFinishedFiles();.

@genesistr
Expand|Select|Wrap|Line Numbers
  1. timer = new Timer("load",File.WaitForUnFinishedFiles);
prototype is not necessary when calling the method…
Aug 14 '09 #2
sorry i pasted with wrong function name. it's already file.WaitForUnFinishedFiles();.
Aug 14 '09 #3
Dormilich
8,658 Expert Mod 8TB
other than that the shown code looks fine.
Aug 14 '09 #4
it looks fine for me also but i dont understand why i lost this' objects. i got this error just when i use timer callback method.
Aug 14 '09 #5
gits
5,390 Expert Mod 4TB
i think you somewhere start your timers ... so the code that is executed is:

Expand|Select|Wrap|Line Numbers
  1. Timer.prototype.Start = function() {
  2.     this.timer = self.setTimeout(this.callback, this.interval);
  3.     this.isRunning = true;
  4. }
here you loose the scope of this since the timeout 'unbinds' the function from your current scope. you might (probably) fix that the following way (basicly a closure):

Expand|Select|Wrap|Line Numbers
  1. Timer.prototype.Start = function() {
  2.     var me = this;
  3.  
  4.     this.timer = self.setTimeout(function() {
  5.         me.callback.apply(me, arguments);
  6.     }, this.interval);
  7.  
  8.     this.isRunning = true;
  9. }
kind regards
Aug 15 '09 #6
gits
5,390 Expert Mod 4TB
hi ... since you pmed me that you have further problems with it i had a closer look at it and now i think you basicly want the this of your file-obj closured ... so you would need to use (the previous answer considered to have the this scope of your timer-obj):

Expand|Select|Wrap|Line Numbers
  1. function File(path) {
  2.     this.fileName = path;
  3.     var me = this;
  4.  
  5.     if (timer == null) {
  6.         timer = new Timer("load", function() {
  7.             me.WaitForUnFinishedFiles.apply(me, arguments);
  8.         });
  9.     }
  10. }
kind regards
Aug 16 '09 #7
gits
5,390 Expert Mod 4TB
aah ... and perhaps you need to initialize your global timer variable to null?
Aug 16 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
11
by: Steve Jorgensen | last post by:
I've recently been playing with some UI ideas that require the user of a timer to drive animation. The problem I'm having is that Access routinely stops firing timer events for long periods of...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
4
by: Daniel | last post by:
Hey guys Here is what i want to do. I have made a multiplayer game that needs to when more than one player is ready start a countdown that the clients can see, so players can still join in this...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
8
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
2
by: Johnny Jörgensen | last post by:
I've got a process I want to run in a thread separate from my main application thread, so I've used a backgroundworker component, and in frmMain.Load I invoke the code using...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.