- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
They better have some damn good hold music if i'm waiting that long
Admin
What's with the int i=1; It's never used!
Admin
Admin
It's in the while loop.
Admin
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."
Admin
Let's pass in a value of 86399 seconds and see what happens.
Admin
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
Admin
It will wait 23 hours, 59 minutes and 59 seconds...
Admin
Erm, 6 hours. And window != IntPtr.Zero seems abusive here.
Admin
they better have one fantastic sales pitch to keep someone on the phone for a week!
Admin
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.
Admin
// 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:
Admin
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)
Admin
Admin
Perhaps it was BT?
http://www.news.com.au/story/0,23599,22270173-401,00.html
Admin
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.
Admin
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
Admin
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.
Admin
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.
Admin
And as usual; the real WTFs are the comments..
Admin
Best obscure simpsons reference ever!
Admin
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.
Admin
I think "The Theme From Shaft" is almost long enough that it won't repeat.
Admin
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%...
Admin
Would this happen to be for the cable company?
Admin
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)
Admin
There is a Tom Petty song that comes to mind too.
Admin
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.
Admin
ROLFLMAO, coffee through nose, pee in my pants, and puke!
Admin
Try again: 'max' is initialized to '86400 * 4' so it will wait a day, not 8 hours.
Admin
lol
Admin
lol
Admin
Admin
Admin
public static IntPtr GetWindow(string className, string title, int maxWaitInSeconds, IntPtr avoidWindow) { IntPtr window = IntPtr.Zero; int max = 86400 * 4; int i = 0;
}
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}
Admin
Admin
TRWTF is the math skills of the people commenting:
Admin
http://www.shortnews.com/start.cfm?id=64390
Admin
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(); }
Admin
60 * 60 * 24 = 86400
Admin
Unless a week on your planet is equal to one Earth day, you need to check your math.
Admin
Exactly. One week. Sheesh.
Admin
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.
Admin
Admin
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.
The times they are a'changin'.
Admin
Yeah, count me in as another person who didn't know there were more than 24-hours in a day....
Admin
Does nobody understand Zygo's comment?
Admin
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.
Admin
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>
Admin
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.