From: Goran on
On Apr 29, 1:55 pm, Simon <b...(a)example.com> wrote:
> > Pause: no, you can only kill it and set it again.
> > Remaining time: no way that I know of, so you will need to create a
> > mechanic of your own. It's not hard (e.g. remember time of last
> > WM_TIMER and then do long remaining = (lastTick+PERIOD)-Now()).
>
> I see what you are saying.
> I might do something like that.
>
>
>
> > What are you trying to achieve?
>
> Yes, I am fairly sure I need it.
> We have some use cases to 'pause', (or delay), a timer.
> Here is a common example.
>
> We have a server application, when it starts, it checks online for new
> transactions every 10 minutes.
>
> During those 10 minutes the user can start a time consuming process,
> (printing of reports, connecting to another app, doing a backup), during
> the process we do not want to check for transactions.
>
> What I could do is:
>
> OnTimer()
> {
>   if( busy_doing_something_important )
>   {
>     // check again in 10 seconds
>   }
>   else
>   {
>     check_for_transactions()
>   }
>
> }

Well, your example absolutely begs the question: what's wrong with
doing "check_for_transactions()" in another thread? (IOW, if this is
your situation, then who cares about a timer!? Spawn a thread for
either, or even both operations. Sure, first rule of multithreading is
"don't", but if you have anything on the lines of a long-running
procedure, that rule easily rules itself out.

Goran.
From: Tom Serface on


"Simon" <bad(a)example.com> wrote in message
news:#n8kUL55KHA.5476(a)TK2MSFTNGP06.phx.gbl...

> Yes, I am fairly sure I need it.
> We have some use cases to 'pause', (or delay), a timer.
> Here is a common example.
>
> We have a server application, when it starts, it checks online for new
> transactions every 10 minutes.

You could do all of this in the same timer just based on other
flags/sub-timers that you set while in here. What you really need to do is
make the firing of the timer be the shortest resolution you might need.
Having it fire the timer then just returning since enough time has elapsed
is not an expensive operation.

>
> During those 10 minutes the user can start a time consuming process,
> (printing of reports, connecting to another app, doing a backup), during
> the process we do not want to check for transactions.

I would just set a busy flag in these cases which would preclude doing the
check while something else is going on.

>
> What I could do is:
>
> OnTimer()
> {
> if( busy_doing_something_important )
> {
> // check again in 10 seconds
> }
> else
> {
> check_for_transactions()
> }
> }
Yeah, like that, only you may want to have it check more than every 10
minutes.

> Or I could kill the timer and restart it again, but if the user print a
> new report every 9:59 minutes then there will be no checks for a very long
> time.

The problem with killing the timer is you'd need a way to restart it. You
could do this when the report finishes printing, or some other operation,
but that may take longer than you want.

> On the other hand, if I check for transactions every time we complete a
> lengthy transaction then we might end-up checking too often, (during month
> end for example we print hundreds of reports).

Unless the check takes a really long time I don't think this will be an
issue.
>
> So on return of a lengthy operation I could check if the timer would have
> fired, and in that case check for transactions.

That would work so long as you're only doing one report at a time, or you
could, as you said, stop the timer while a report is printing then restart
it when the report completes or is canceled (assuming there is only one
running).

Tom


From: Tom Serface on
I think OP's use of the timer is really more minimal than it looks. He just
wants to have it check to see if something is queued (if I'm reading it
right) then do that. Looks like the check doesn't need to be done while
something is happening (like a report is running) so the timer could safely
be stopped during that operation.

I agree with you that a thread may be easier to manage since there would be
no reason to stop it once it's running. It could just send a user message
to the UI when something needs to happen and that message could be handled
pretty easily in the UI thread.

Still, for something this simple, the timer idea works OK.

Tom

"Goran" <goran.pusic(a)gmail.com> wrote in message
news:0c0d25fe-5cdb-42a9-b7d5-601d12a67d4e(a)r11g2000yqa.googlegroups.com...
> On Apr 29, 1:55 pm, Simon <b...(a)example.com> wrote:
>> > Pause: no, you can only kill it and set it again.
>> > Remaining time: no way that I know of, so you will need to create a
>> > mechanic of your own. It's not hard (e.g. remember time of last
>> > WM_TIMER and then do long remaining = (lastTick+PERIOD)-Now()).
>>
>> I see what you are saying.
>> I might do something like that.
>>
>>
>>
>> > What are you trying to achieve?
>>
>> Yes, I am fairly sure I need it.
>> We have some use cases to 'pause', (or delay), a timer.
>> Here is a common example.
>>
>> We have a server application, when it starts, it checks online for new
>> transactions every 10 minutes.
>>
>> During those 10 minutes the user can start a time consuming process,
>> (printing of reports, connecting to another app, doing a backup), during
>> the process we do not want to check for transactions.
>>
>> What I could do is:
>>
>> OnTimer()
>> {
>> if( busy_doing_something_important )
>> {
>> // check again in 10 seconds
>> }
>> else
>> {
>> check_for_transactions()
>> }
>>
>> }
>
> Well, your example absolutely begs the question: what's wrong with
> doing "check_for_transactions()" in another thread? (IOW, if this is
> your situation, then who cares about a timer!? Spawn a thread for
> either, or even both operations. Sure, first rule of multithreading is
> "don't", but if you have anything on the lines of a long-running
> procedure, that rule easily rules itself out.
>
> Goran.

From: Joseph M. Newcomer on
See below...
On Thu, 29 Apr 2010 11:29:40 +0200, Simon <bad(a)example.com> wrote:

>Hi,
>
>I am fairly sure there isn't a straight forward way to do it but I
>thought I'd ask more knowledgeable people here first.
>
>let say I create a timer for 10 minutes.
>
>::SetTimer( m_hWnd, TIMER_IDENT, 600000, NULL ); // WM_TIMER sent to
>CWnd queue
>
>Is it possible to 'pause' the timer
***
No.
****
>or at know how many ms are left
>before the WM_TIMER event is fired?
****
No

What are you trying to do? There may be other ways to handle it. Note that WM_TIMER is
not even a particularly accurate or even reliable mechanism.
joe
****

>
>Many thanks
>
>Simon
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
See below...
On Thu, 29 Apr 2010 13:55:12 +0200, Simon <bad(a)example.com> wrote:

>> Pause: no, you can only kill it and set it again.
>> Remaining time: no way that I know of, so you will need to create a
>> mechanic of your own. It's not hard (e.g. remember time of last
>> WM_TIMER and then do long remaining = (lastTick+PERIOD)-Now()).
>
>I see what you are saying.
>I might do something like that.
>
>>
>> What are you trying to achieve?
>
>Yes, I am fairly sure I need it.
>We have some use cases to 'pause', (or delay), a timer.
>Here is a common example.
>
>We have a server application, when it starts, it checks online for new
>transactions every 10 minutes.
>
>During those 10 minutes the user can start a time consuming process,
>(printing of reports, connecting to another app, doing a backup), during
>the process we do not want to check for transactions.
>
>What I could do is:
>
>OnTimer()
>{
> if( busy_doing_something_important )
> {
> // check again in 10 seconds
> }
> else
> {
> check_for_transactions()
> }
>}
>
>Or I could kill the timer and restart it again, but if the user print a
>new report every 9:59 minutes then there will be no checks for a very
>long time.
>
>On the other hand, if I check for transactions every time we complete a
>lengthy transaction then we might end-up checking too often, (during
>month end for example we print hundreds of reports).
>
>So on return of a lengthy operation I could check if the timer would
>have fired, and in that case check for transactions.
>
>Regards
****
This is what happens when you ask an implementation question instead of stating a problem.

It is very simple:

Whenever you want to restart the timer, you do two things:
Record the current time (as a time_t)
SetTimer for 10 minutes
When you are done, you look at the recorded time and compare it to the current time, and
take action based on that.

One of the questions is why the check is so expensive? If a transaction comes in, put it
in a queue and set a BOOL to TRUE. Or have a thread which is using
GetQueuedCompletionStatus and use PostQueuedCompletionStatus to post new events to it.

You can even set a 10-minute timeout on the GetQueuedCompletionStatus so if nothing has
happened you will get control.

Note that you can't use the 32-bit tick count because if it wraps back to 0, you will get
incorrect results unless you deal with this problem.
joe
>
>Simon
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: _in s and _out s ?
Next: MSI Serial Number Validation