Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 675
  • Last Modified:

How to use OnIdle()?

How to use OnIdle() of CWinApp()? I have tried it but it doesn't work.
I'm now trying to write a server that would close the connection of a client if the client has idled for a long time. So, the server has to be able to time the idle time.
How can I archieve this?
I know that there is one more function called settimer()but how to use it?
Thanks a lot.
0
syyung6
Asked:
syyung6
  • 4
  • 2
1 Solution
 
fRouxSerretCommented:
For the function to be called, it has to be declared in the message map of the corresponding window (ON_WM_IDLE, or somthing like this...)
The timer function has to be declared too (ON_WM_TIMER). Then, you call the SetTimer() on your window, with a given time in milliseconds, and after this time, your window's OnTimer() (I'm not sure of the name of the function) function is called. If you want to be called again, you have to call again SetTimer() at the end of the OnTimer() function.

If neither of these things work, then try this:

Edit your window's callback function, and add a 'case' statement for each message you want to process. write some code (break for example), and add a breakPoint on this line. If the breakPoint is never reached, then Windows uses a different callBack function: You just have to find it, or to find a way to redirect it (Look at your window class definition, and at the window opening code).

Hope it helps !!

0
 
md041797Commented:
" If you want to be called again, you have to call again SetTimer() at the end of the OnTimer() function."

Windows timers are free running.  Don't reset after each timeout.  They will continue timing out until you call KillTimer.  If you SetTimer after each time event, you will soon run out of resources, because a new timer is created each call.


0
 
fRouxSerretCommented:
It seems that md doesn't like me !!!!! ;-)

However he's right and wrong: I checked in the docs:

YES : I appologize, SetTimer doesn't need to be called again after each event ! It sends events until KillTimer is called.

NO: you won't run out of resource if you use 'SetTimer' again, because with the same timer ID, it will either use the memory of the previously allocated Timer, or return an error code, without wasting some memory.

Thank you for correcting me !
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fRouxSerretCommented:
It seems that md doesn't like me !!!!! ;-)

However he's right and wrong: I checked in the docs:

YES : I appologize, SetTimer doesn't need to be called again after each event ! It sends events until KillTimer is called.

NO: you won't run out of resource if you use 'SetTimer' again, because with the same timer ID, it will either use the memory of the previously allocated Timer, or return an error code, without wasting some memory.

Thank you for correcting me !
0
 
fRouxSerretCommented:
Oooooops !
0
 
md041797Commented:
No, I'm just being a butt-head.
0
 
syyung6Author Commented:
Thank you very much for helping me.
Actually, I've solved the problem by using OnTimer(), ON_WM_TIMER, and SetTimer().
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now