Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Is this dodgy?

  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is this dodgy?

    I don't know, do 'real programs' often loop endlessly until some condition is met? This seems to be the only way from script, but it's questionable, so I'm asking.


    Code:
    var theObject = WScript.CreateObject('ProgID', "theObject_");
    
    function theObject_onFoo()
    {
    	// doThis...
    }
    
    function theObject_onBar()
    {
    	// doThat...
    }
    
    while(typeof theObject.property != "unknown")
    	WScript.Sleep(1000);
    Last edited by codegoboom; 01-09-2005 at 05:05 PM. Reason: Geez, can't even write pseudo code w/out error!
    *this message will self destruct in n-seconds*

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe I should explain that the sleep loop keeps wscript.exe from terminating in the usual imperative fashion, and while it is sleeping, however many events from the automation object may be firing, and while the event functions are doing their thing, wscript is running those, and waking up again, etc.
    How chaotic is that?
    *this message will self destruct in n-seconds*

  • #3
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    it's pretty normal for a program to wait until something happens, but there are better ways of doing it, i think.

    i think the method that i would use, would be setInterval, and then clearInterval once the property changed. i'd do it that way because i'm imagining that it would be much less processor-intensive, though i'm not basing that on anything at all.

    other than the difference in methodology, though, i don't see anything wrong with it.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's just that the WScript object has no window methods, so Sleep() is all there is. But now that you mention it, I suppose it's all the same no matter what type of (or how many) objects/models are being manipulated.
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •