• Tim (unregistered)

    They better have some damn good hold music if i'm waiting that long

  • Frank (unregistered) in reply to Tim

    What's with the int i=1; It's never used!

  • nobody (unregistered) in reply to Tim
    Tim:
    They better have some damn good hold music if i'm waiting that long
    I'm sure they have something like "The Best of Captain Beefheart" or maybe they went in a different direction with "Lawrence Welk's Greatest Hits"
  • (cs) in reply to Frank
    Frank:
    What's with the int i=1; It's never used!

    It's in the while loop.

  • keezer (unregistered)

    Arrrgghhh. How about "Do you know the way to San Jose?" arranged for synth sax mixed with the 30 second chiming in of the company message, "Your call is important to us. Please hold and a representative will be with you shortly."

  • (cs)

    Let's pass in a value of 86399 seconds and see what happens.

  • lightinthedark (unregistered)

    From the looks of it, if you tried to tell it to wait more than a day it'd ignore you and just set max to 86400 * 4 again. How rude! :-) And the i=0 initialises the counter that gets checked down near the bottom in the while loop ... i < max ...

    Hello :-Lightinthedark

  • (cs) in reply to ucltech
    ucltech:
    Let's pass in a value of 86399 seconds and see what happens.

    It will wait 23 hours, 59 minutes and 59 seconds...

  • somebody (unregistered)

    Erm, 6 hours. And window != IntPtr.Zero seems abusive here.

  • (cs)
    int max = 86400 * 4;
    ...
    && (i++ < max))
    ...
    Thread.Sleep(250);
    

    they better have one fantastic sales pitch to keep someone on the phone for a week!

  • (cs)

    You can't put me on hold, I'll put you on hold. (singing) I am a lineman for the county. (speaking) Your call is important to us. Please continue to hold. (singing) And I drive the main road. (speaking) There are…eight calls ahead of you. (singing) And the Wichita lineman is still on the li-li-li-li-li-li-li-li-li-li-li-li-line.

  • Jimmy (unregistered)

    // 86400 is the number of seconds in a day int max = 86400 * 4;

    Since they increase the number of seconds to wait by multiplying it with 4 wouldn't that mean that we wait 4 days instead of just one lousy day. :)

    I can image the discussion about the wait time:

    • Hmm how long should we keep trying?
    • Well maybe a few minutes are enough.
    • What if the system is VERY busy?
    • Ok, what about max wait time of one hour?
    • Set it to a full day and we'll get back to this. ... later
    • What was it that architect told me? Lets be on the safe side and put the wait time to four days. ... even later
    • What was it we were supposed to change???
  • N2 (unregistered) in reply to Jimmy
    Jimmy:
    // 86400 is the number of seconds in a day int max = 86400 * 4;

    Since they increase the number of seconds to wait by multiplying it with 4 wouldn't that mean that we wait 4 days instead of just one lousy day. :)

    I can image the discussion about the wait time:

    • Hmm how long should we keep trying?
    • Well maybe a few minutes are enough.
    • What if the system is VERY busy?
    • Ok, what about max wait time of one hour?
    • Set it to a full day and we'll get back to this. ... later
    • What was it that architect told me? Lets be on the safe side and put the wait time to four days. ... even later
    • What was it we were supposed to change???

    Its not 4 days because it tries to find the window 4 times a second, and increments i with each one. (250ms = 1/4th second)

  • (cs) in reply to Jimmy
    Jimmy:
    // 86400 is the number of seconds in a day int max = 86400 * 4;

    Since they increase the number of seconds to wait by multiplying it with 4 wouldn't that mean that we wait 4 days instead of just one lousy day. :)

    No, because they sleep for 250 milliseconds, which is .25 seconds.
  • Andrew (unregistered)

    Perhaps it was BT?

    http://www.news.com.au/story/0,23599,22270173-401,00.html

  • Ben Hutchings (unregistered)

    Not only does it use an inappropriate time limit; but it uses FindWindow and ignores a certain result (avoidWindow). What if there are two matching windows and FindWindow always returns avoidWindow? I think that may well be why it doesn't return quickly. This should be using EnumWindows or whatever wrapper .NET has for it. Also, messing with other process's windows is something of a WTF (window handles aren't ref-counted!) though sadly it seems to be necessary too often on Windows.

  • Daniel Pitts (unregistered)

    The Real WTF is the analysis of this code...

    It tries every 1/4 second to find the window, for a full day. The fact that it gives a full day time before it gives up is a bit of a "Hmm", but not a WTF.

    Captcha: poindexter

  • Crabs (unregistered)

    Seems like you pass a maximum amount of time you're willing to wait. The maximum time that can be is 1 day. Doesn't seem so ridiculous...Yeah, a day's a bit long, but the max has to be somewhere, and this guy is expecting a smaller value to be passed. At least he's doing some sort of input validation.

  • Anonymous (unregistered)
    The fact that it gives a full day time before it gives up is a bit of a "Hmm", but not a WTF.

    You always give a non-responsive application 25 hours to recover before you declare it dead? I bow in respect of your patience.

    Using an infinite loop would have had exactly the same effect for the user. Waiting a full day is clearly a WTF.

  • (cs)

    And as usual; the real WTFs are the comments..

  • homer (unregistered) in reply to jgayhart
    jgayhart:
    You can't put me on hold, I'll put you on hold. (singing) I am a lineman for the county. (speaking) Your call is important to us. Please continue to hold. (singing) And I drive the main road. (speaking) There are…eight calls ahead of you. (singing) And the Wichita lineman is still on the li-li-li-li-li-li-li-li-li-li-li-li-line.

    Best obscure simpsons reference ever!

  • wtf (unregistered) in reply to Anonymous

    But a full day is only the default, and the max accepted interval. Callers can provide a shorter interval if they want.

    What's wrong with this?

    It seems the real WTF isn't in the code shown, but in the calling function, and that it relies on the default. Still not a big deal.

    A bigger WTF in my book is the way he measures time - a certain number of sleep(250) can't be accurate: clock resolution rounding might make each sleep actually 233 or 266ms or some other arbitrary period; the surrounding code also takes time to execute; there may be other delays caused by other processes or I/O; also, perhaps (not sure on windows) sleep can be interrupted earlier by signals and such.

  • Andrew (unregistered) in reply to Tim
    Tim:
    They better have some damn good hold music if i'm waiting that long

    I think "The Theme From Shaft" is almost long enough that it won't repeat.

  • (cs)

    The code is already optimized and noone sa<w it. It uses the upper bound of the if statement. This means it will NOT multiply the timer by 4. So effectively it will only wait 8 H with the call...

    But if you pass in 1 second LESS, then you will increase the waittime by almost 300%...

  • Andrew (unregistered)

    Would this happen to be for the cable company?

  • anon (unregistered)

    It's behavior is "I will wait a day unless you give me a time less than a day.", which is fine (other than being a large maximum).
    i.e. It is setting "max" to be the 4 * minimum of (maxWaitInSeconds and dayInSeconds)

  • Andrew (unregistered) in reply to Tim
    Tim:
    They better have some damn good hold music if i'm waiting that long

    There is a Tom Petty song that comes to mind too.

  • jkupski (unregistered) in reply to Andrew
    Andrew:
    Would this happen to be for the cable company?

    No. If it was, the max wait time would be random, and there would be a 20% chance of dropping your call on every iteration of the loop.

    And remember, folks: when the cable company says "We'll be there Friday, 9-1" they aren't telling you when they will arrive... they're quoting odds.

  • Andrew (unregistered) in reply to jkupski
    jkupski:
    Andrew:
    Would this happen to be for the cable company?

    No. If it was, the max wait time would be random, and there would be a 20% chance of dropping your call on every iteration of the loop.

    And remember, folks: when the cable company says "We'll be there Friday, 9-1" they aren't telling you when they will arrive... they're quoting odds.

    ROLFLMAO, coffee through nose, pee in my pants, and puke!

  • woofles (unregistered) in reply to rdrunner
    rdrunner:
    The code is already optimized and noone sa<w it. It uses the upper bound of the if statement. This means it will NOT multiply the timer by 4. So effectively it will only wait 8 H with the call... <p>But if you pass in 1 second LESS, then you will increase the waittime by almost 300%...

    Try again: 'max' is initialized to '86400 * 4' so it will wait a day, not 8 hours.

  • Cloak (unregistered) in reply to Evo
    Evo:
    And as usual; the real WTFs are the comments..

    lol

  • Cloak (unregistered) in reply to Evo
    Evo:
    And as usual; the real WTFs are the comments..

    lol

  • dkf (unregistered) in reply to Andrew
    Andrew:
    Would this happen to be for the cable company?
    Or AT&T? (Motto: We don't have to care, we're the phone company.)
  • nobody (unregistered) in reply to dkf
    dkf:
    Andrew:
    Would this happen to be for the cable company?
    Or AT&T? (Motto: We don't have to care, we're the phone company.)
    For a while, ATT No-Broadband was my cable company. A few people actually were able to get to customer "service", after waiting over 40 minutes. Just about everyone else gave up.
  • Mexi-Fry (unregistered)

    public static IntPtr GetWindow(string className, string title, int maxWaitInSeconds, IntPtr avoidWindow) { IntPtr window = IntPtr.Zero; int max = 86400 * 4; int i = 0;

    // 86400 is the number of seconds in a day
    
    if (maxWaitInSeconds < 86400) 
    {
        max = maxWaitInSeconds * 4;
    }
    
    window = Win32API.FindWindow(className, title);
    
    while ( ((window == IntPtr.Zero) 
              || (window != IntPtr.Zero && window == avoidWindow)) 
           && (i++ < max))
    {
        Thread.Sleep(250);
        window = Win32API.FindWindow(className, title);
    }    
    return window;
    

    }

    Actually, this code seems to suggest that it will wait up to a day for a handle to a window. It apparently tries 4 times per second. A bit silly, but this seems like a small matter compared to enum x {yes=0,no=1}

  • Mexi-Fry (unregistered) in reply to Mexi-Fry
    Mexi-Fry:
    public static IntPtr GetWindow(string className, string title, int maxWaitInSeconds, IntPtr avoidWindow) { IntPtr window = IntPtr.Zero; int max = 86400 * 4; int i = 0;
    // 86400 is the number of seconds in a day
    
    if (maxWaitInSeconds < 86400) 
    {
        max = maxWaitInSeconds * 4;
    }
    
    window = Win32API.FindWindow(className, title);
    
    while ( ((window == IntPtr.Zero) 
              || (window != IntPtr.Zero && window == avoidWindow)) 
           && (i++ < max))
    {
        Thread.Sleep(250);
        window = Win32API.FindWindow(className, title);
    }    
    return window;
    

    }

    Actually, this code seems to suggest that it will wait up to a day for a handle to a window. It apparently tries 4 times per second. A bit silly, but this seems like a small matter compared to enum x {yes=0,no=1}

    Clarification: UP TO... to be sure that I said it right. If the window was closed and is no longer retrievable, then the application will never pass that point, but if it manages to get a reference in the first second, or ten minutes it will. Still seems silly to me... but a training issue could get around that bug.

  • Zygo (unregistered)

    TRWTF is the math skills of the people commenting:

    1. There are 86400 seconds in a week.
    2. There are 31 hours, 59 minutes, 59.75 seconds in a day.
    3. Code on Windows that calls Sleep(250) 86400 times will take only one day to execute.
  • Seb (unregistered)

    http://www.shortnews.com/start.cfm?id=64390

  • Andrew (unregistered) in reply to dkf
    dkf:
    Andrew:
    Would this happen to be for the cable company?
    Or AT&T? (Motto: We don't have to care, we're the phone company.)

    Well, there's a missing segment of code

    while (customer.minutesLeft() > 0) { music.play(); announcer.annoy(); // Tells the customer how important they are ringer.trickRing(); }

  • Andrew (unregistered) in reply to Zygo
    Zygo:
    TRWTF is the math skills of the people commenting:
    1. There are 86400 seconds in a week.
    2. There are 31 hours, 59 minutes, 59.75 seconds in a day.
    3. Code on Windows that calls Sleep(250) 86400 times will take only one day to execute.

    60 * 60 * 24 = 86400

  • (cs) in reply to Zygo
    Zygo:
    1. There are 86400 seconds in a week.

    Unless a week on your planet is equal to one Earth day, you need to check your math.

  • gomer (unregistered) in reply to Andrew
    Andrew:
    Zygo:
    TRWTF is the math skills of the people commenting:
    1. There are 86400 seconds in a week.
    2. There are 31 hours, 59 minutes, 59.75 seconds in a day.
    3. Code on Windows that calls Sleep(250) 86400 times will take only one day to execute.

    60 * 60 * 24 = 86400

    Exactly. One week. Sheesh.

  • (cs) in reply to Someone You Know
    Someone You Know:
    Zygo:
    1. There are 86400 seconds in a week.

    Unless a week on your planet is equal to one Earth day, you need to check your math.

    He was remarking on "the math skills of the people commenting". I think he himself is aware of the correct significance of the number 86400.

  • herman (unregistered) in reply to Zygo
    Zygo:
    TRWTF is the math skills of the people commenting:
    1. There are 86400 seconds in a week.
    2. There are 31 hours, 59 minutes, 59.75 seconds in a day.
    3. Code on Windows that calls Sleep(250) 86400 times will take only one day to execute.
    I knew the rotationspeed of the Earth was retarding but that it was now 8 hours longer then when I was born in 1951 I did not know. Thanks for this insight
  • AdT (unregistered)

    This should actually wait longer than a day (unless it finds the window) because of scheduling delays and the time it takes to execute the loop 86400 * 4 times. 86400 seconds that's just the raw sleep() time.

    herman:
    I knew the rotationspeed of the Earth was retarding but that it was now 8 hours longer then when I was born in 1951 I did not know. Thanks for this insight

    The times they are a'changin'.

  • (cs)

    Yeah, count me in as another person who didn't know there were more than 24-hours in a day....

  • (cs)

    Does nobody understand Zygo's comment?

  • (cs) in reply to jread

    If we had 32 days, and the days were composed of 32 hours with 64 minutes, each containing 64 seconds, each containing 1024 milliseconds, then each month would start at 0x...00000000 and end at 0x...ffffffff. It'd be cool and thrilling and generally nifty, and programmers could tell the time.

    My name is arty, and I approved this message.

  • Harrow (unregistered)

    Assuming the following specification, the code is correct:

    If you want to get the handle of a specified window by title, but not if it is a certain window handle you already have, and you only want to wait a specified number of seconds, then call

    GetWindow( <classname>, <title>, <seconds>, <butnotthisone> )</butnotthisone></seconds>

    Note: If you pass a time period that is more than 24 hours, it will be truncated to 24 hours.

    Your application never passes a time anywhere near that long. If it does, there's a coding error, and the very long default insures that you will notice the problem while testing (especially as this a telco, and "testing" is performed by the customers during the first few days after deployment).

    But if you want to get the handle of a specified window by title, and will accept any window handle, and you are willing to wait "forever", then call

    GetWindow( <classname>, <title> )</p> <p>Note: it won't wait forever, but will wait 24 hours.</p> <p>Since you only use this call one time, during application startup, there should be no problem, If the application fails to start, you have a whole day to hunt down the frozen process and find out what went wrong.</p> <p>-Harrow.</p> </title></classname>

  • Mogri (unregistered) in reply to gomer
    Andrew:
    Zygo:
    TRWTF is the math skills of the people commenting:
    1. There are 86400 seconds in a week.
    2. There are 31 hours, 59 minutes, 59.75 seconds in a day.
    3. Code on Windows that calls Sleep(250) 86400 times will take only one day to execute.

    60 * 60 * 24 = 86400

    It's odd that everyone gets hung up on point 1 and misses point 2. I'm not sure what Zygo was getting at, but he wasn't being serious. None of the three points above is correct.

Leave a comment on “Patiently Waiting Forever”

Log In or post as a guest

Replying to comment #150357:

« Return to Article