I have a Timer in a C# app (Win7 64). Every 20 min the timer callback gets some data via HTTP. It works well. But if my PC goes to sleep for a few hours, then wakes up, I get an HTTP error saying "can't find the server". The server is running at all times, so it's not the real issue. I suspect the real reason is that as the timer callback misses its "time slot" during the sleep period, it becomes "overdue" and is executed instantly right after the wake-up, without waiting for the PC to re-establish the Internet connection. I can fix the problem by adding a Thread.Sleep(5000) at the beginning of the callback, but it's a bit of a kludge (establishing Internet connection might take longer). My questions:
After a wake-up from sleep mode, does Win indeed need a few seconds to re-establish Internet connection? My connection is DSL, "always online".
Is there a C# system call which would wait until Win establishes the Internet connection (or time out if this doesn't happen within, say, 20 secs)?
EDIT: Just found this: Check Net connection in C#. Not as simple as I hoped, it takes a sequence of checks: any LAN connection, DNS lookup (outside the LAN), ping a server (check a particular server).