D - timer
- Carlos Santander B. (13/13) Mar 27 2003 Hi,
-
Carlos Santander B.
(29/29)
Mar 27 2003
"Carlos Santander B."
escribiσ en el mensaje - Matthew Wilson (16/29) Mar 27 2003 If you're on an NT-family box exclusively you can use timer objects - se...
-
Carlos Santander B.
(73/73)
Mar 27 2003
"Matthew Wilson"
escribiσ en el mensaje - Jon Allen (17/90) Mar 27 2003 SetTimer is the solution I usually use, just because it's easy. That be...
- J C Calvarese (6/8) Mar 27 2003 Phobos has a "thread" module (which in turn has a Thread class). I'm
Hi, I'm writing a distributed application where the clients won't have an interface, they'll only run in background mode. When the server is not connected, the clients have to try to find it every 5 minutes. How can I do that? I mean, I know there're the timer functions in the Windows API (SetTimer, etc.), but they need a window handle, which obviously I won't have. Any help would be greatly appreciated. ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
"Carlos Santander B." <carlos8294 msn.com> escribiσ en el mensaje news:b5vb3t$1vm6$1 digitaldaemon.com... | Hi, | I'm writing a distributed application where the clients won't have an | interface, they'll only run in background mode. When the server is not | connected, the clients have to try to find it every 5 minutes. How can I do | that? I mean, I know there're the timer functions in the Windows API | (SetTimer, etc.), but they need a window handle, which obviously I won't | have. Any help would be greatly appreciated. | | ------------------------- | Carlos Santander | | | --- | Outgoing mail is certified Virus Free. | Checked by AVG anti-virus system (http://www.grisoft.com). | Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25 | | Ok, no need to bother anymore. I already got this. MSDN is more powerful than you'd expect... Thanks anyway. Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
If you're on an NT-family box exclusively you can use timer objects - see CreateWaitableTimer() If you're on either 9x or NT, then you would have to have a worker thread waiting for your timeout period on a kernel object - e.g. a mutex or an event - that was never signalled. Each time it times out, you have your 5 min wait. The worker thread would signal the main thread by sending a thread message, or window message, or setting an event, or whatever. This setup can work well when you want to terminate cleanly, as you can use the signalling of the timeout object as the worker termination command. I'd be very keen to see your work on either of these things. On a more general note, can anyone inform on what support D has for thread creation and synchronisation? Matthew "Carlos Santander B." <carlos8294 msn.com> wrote in message news:b5vb3t$1vm6$1 digitaldaemon.com...Hi, I'm writing a distributed application where the clients won't have an interface, they'll only run in background mode. When the server is not connected, the clients have to try to find it every 5 minutes. How can Idothat? I mean, I know there're the timer functions in the Windows API (SetTimer, etc.), but they need a window handle, which obviously I won't have. Any help would be greatly appreciated. ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
"Matthew Wilson" <dmd synesis.com.au> escribiσ en el mensaje news:b5vrkv$2edp$1 digitaldaemon.com... | If you're on an NT-family box exclusively you can use timer objects - see | CreateWaitableTimer() | | If you're on either 9x or NT, then you would have to have a worker thread | waiting for your timeout period on a kernel object - e.g. a mutex or an | event - that was never signalled. Each time it times out, you have your 5 | min wait. The worker thread would signal the main thread by sending a thread | message, or window message, or setting an event, or whatever. This setup can | work well when you want to terminate cleanly, as you can use the signalling | of the timeout object as the worker termination command. | | I'd be very keen to see your work on either of these things. | | On a more general note, can anyone inform on what support D has for thread | creation and synchronisation? | | Matthew | | "Carlos Santander B." <carlos8294 msn.com> wrote in message | news:b5vb3t$1vm6$1 digitaldaemon.com... | > Hi, | > I'm writing a distributed application where the clients won't have an | > interface, they'll only run in background mode. When the server is not | > connected, the clients have to try to find it every 5 minutes. How can I | do | > that? I mean, I know there're the timer functions in the Windows API | > (SetTimer, etc.), but they need a window handle, which obviously I won't | > have. Any help would be greatly appreciated. | > | > ------------------------- | > Carlos Santander | > | > | > --- | > Outgoing mail is certified Virus Free. | > Checked by AVG anti-virus system (http://www.grisoft.com). | > Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25 | > | > | | In fact, I went for an easier way (IMHO, at least): void wait() { MSG msg; SetTimer(NULL,0,300000,(TIMERPROC) MyTimerProc); while (GetMessageA(&msg,NULL,NULL,NULL)) { if (msg.message == WM_TIMER) msg.hwnd = NULL; TranslateMessage(&msg); DispatchMessageA(&msg); if (info.sock!==null) { KillTimer(NULL,0); return; } } } void mtp(HWND hwnd,UINT message,UINT idTimer,DWORD dwTime) { ... } My first choice was to put mtp() inside wait(), and it actually worked. But mtp() calls another function, which is outside wait() and it wasn't being called for some reason that I don't know about. That's why I had to put it outside. From a professional POV, is my solution better or worse than those that you suggested me? Because I just have no idea... Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
SetTimer is the solution I usually use, just because it's easy. That being said I've heard that using a second thread as a timer is is more accurate. I don't know on what basis that claim is made, or even if it's true or not though. I'm guessing it has something to do with legacy code in 9x not updating the timer chip as often as it could, leaving us with a resolution of only 55ms. I'm not sure how threads would get around this though. Maybe something in the WaitForObjects functions does something really neat? "Carlos Santander B." <carlos8294 msn.com> wrote in message news:b5vslt$2feo$1 digitaldaemon.com..."Matthew Wilson" <dmd synesis.com.au> escribiσ en el mensaje news:b5vrkv$2edp$1 digitaldaemon.com... | If you're on an NT-family box exclusively you can use timer objects -see| CreateWaitableTimer() | | If you're on either 9x or NT, then you would have to have a workerthread| waiting for your timeout period on a kernel object - e.g. a mutex or an | event - that was never signalled. Each time it times out, you have your5| min wait. The worker thread would signal the main thread by sending a thread | message, or window message, or setting an event, or whatever. This setup can | work well when you want to terminate cleanly, as you can use the signalling | of the timeout object as the worker termination command. | | I'd be very keen to see your work on either of these things. | | On a more general note, can anyone inform on what support D has forthread| creation and synchronisation? | | Matthew | | "Carlos Santander B." <carlos8294 msn.com> wrote in message | news:b5vb3t$1vm6$1 digitaldaemon.com... | > Hi, | > I'm writing a distributed application where the clients won't have an | > interface, they'll only run in background mode. When the server is not | > connected, the clients have to try to find it every 5 minutes. How canI| do | > that? I mean, I know there're the timer functions in the Windows API | > (SetTimer, etc.), but they need a window handle, which obviously Iwon't| > have. Any help would be greatly appreciated. | > | > ------------------------- | > Carlos Santander | > | > | > --- | > Outgoing mail is certified Virus Free. | > Checked by AVG anti-virus system (http://www.grisoft.com). | > Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25 | > | > | | In fact, I went for an easier way (IMHO, at least): void wait() { MSG msg; SetTimer(NULL,0,300000,(TIMERPROC) MyTimerProc); while (GetMessageA(&msg,NULL,NULL,NULL)) { if (msg.message == WM_TIMER) msg.hwnd = NULL; TranslateMessage(&msg); DispatchMessageA(&msg); if (info.sock!==null) { KillTimer(NULL,0); return; } } } void mtp(HWND hwnd,UINT message,UINT idTimer,DWORD dwTime) { ... } My first choice was to put mtp() inside wait(), and it actually worked.Butmtp() calls another function, which is outside wait() and it wasn't being called for some reason that I don't know about. That's why I had to put it outside. From a professional POV, is my solution better or worse than those thatyousuggested me? Because I just have no idea... ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
Matthew Wilson wrote: ...snipOn a more general note, can anyone inform on what support D has for thread creation and synchronisation?Phobos has a "thread" module (which in turn has a Thread class). I'm guessing this is what you're looking for. http://www.digitalmars.com/d/phobos.html#thread Justin
Mar 27 2003