From: Joseph M. Newcomer on
See bekiw,,,
On Fri, 30 Apr 2010 17:35:24 +0200, Simon <bad(a)example.com> wrote:

>
>> Note that if this is a long computation in the main GUI thread, that you have not returned
>> to the message pump, and consequently no timer messages could have been processed, and
>> therefoere if the timer_is_complete flag was not set when you entered, it cannot be set
>> when you leave.
>
>It is not in the main GUI thread.
****
According to your example, it is shown as being in a thread that requires a message pump
for correct behavior. If DoSomething() means something else, then it should not be
illustrated as if it is a subroutine call in a thread, and the architecture needs a better
description for the code snippet you gave to make sense.
****
>
>>
>> And you should not compare a bool variable to a bool literal; this is poor style. What
>> value to you think a bool variable has? And why aren't you just saying
>
>This is your style, I don't agree with it.
>
>> Well, Microsoft did not take your happiness into consideration.
>
>Didn't ask for it.
>
>>>
>>> I could write my own timer class using a thread but this would add a lot
>>> over testing overhead to the current app.
>> ****
>> Without a thread to do the work, the above code is pretty meaningless.
>
>That does not mean anything.
****
Yes it does mean something. It means that if you are not using a thread to do the
computation, if you are not getting the message pump active during the DoSomething, the
code is meaningless, because it relies on an event that can never, ever happen in a real
system. That makes the illustration meaningless. Either it is not an accurate
representation of what you are doing, in which case you gave us a misleading description,
or it is accurate, in which case the code is meaningless.
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
From: Joseph M. Newcomer on
See below....
On Fri, 30 Apr 2010 17:42:38 +0200, Simon <bad(a)example.com> wrote:

>> ****
>> ANd the answers were negative, which meant I couldn't really tell you what might work.
>
>I was happy with the answers, (I started off by assuming it would not work).
>
>> I get tired of trying to outguess what the
>> question actually should have been, so I don't answer if I don't have specification of the
>> problem.
>
>Well then, don't try and throw in your 2p worth in every threads,
>(especially if you don't know)
****
I want to help, but I need sufficient information to make it possible to help.
****
>
>> Then I am very suspect of the design.
>
>No, you are still making the wrong assumptions.
>
>> But when the answers are "it is not possible" then we are left to guess about how the
>> problem might be solved, and not knowing what the problem is means the guesses might be
>> incorrect.
>
>I know, others said it was not possible, (even I guessed it in my OP).
>A discussion started on how a similar behaviour might be possible.
>
>Read some of the replies, some very good suggestions were given.
>
>> ... And there's a difference?
>
>Yes there is. Sorry if you don't know the difference.
>
>>
>> "I need to know how much time has elapsed since I set a timer, because<problem
>> description here>" and the answers are much easier to give.
>
>Maybe with the school projects you work with.
****
Actually, I rarely work with "school projects". I generally work with real clients who
expect a correct, robust, and maintainable solution, and pay me to deliver that.
joe
****
>
>Have a good week-end.
>
>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: Hector Santos on
Simon,

Joe's point was correct and I showed a prime example where the
original post question generated responses that in the end of the day,
weren't really the solutions for you.

The original post generated one solution by me that addressed your
basic overall question - is a pause possible with timers and how.

However, seeing your follow ups with background info, generated a
different solution by me because the OP question really didn't apply
to a solution you were actually seeking.

Note, I am not criticizing you. Just pointing out that how answers
vary which is Joe's point. A little background always helps with
questions people ask otherwise we have to "make guesses" at creating a
solution, especially one where there is no built-in WIN32 solution.
There are no functions like:

::PauseTimer(TIMER_IDENT)
::UnPauseTime(TIMER_IDENT)

Hence, you will get the typical approaches that people have for this:

1) A KillTimer/SetTimer() approach as Goran started:
2) A global timer (always on) with a counter approach as I showed.

Neither were applicable to what you really needed which is a

Atomic Shared Busy Flag with a reference count.

Ita a common construct and that would only be possible to recommend
after knowing what you were trying to do.

--
HLS

Simon wrote:

>> ****
>> ANd the answers were negative, which meant I couldn't really tell you
>> what might work.
>
> I was happy with the answers, (I started off by assuming it would not
> work).
>
>> I get tired of trying to outguess what the
>> question actually should have been, so I don't answer if I don't have
>> specification of the
>> problem.
>
> Well then, don't try and throw in your 2p worth in every threads,
> (especially if you don't know)
>
>> Then I am very suspect of the design.
>
> No, you are still making the wrong assumptions.
>
>> But when the answers are "it is not possible" then we are left to
>> guess about how the
>> problem might be solved, and not knowing what the problem is means the
>> guesses might be
>> incorrect.
>
> I know, others said it was not possible, (even I guessed it in my OP).
> A discussion started on how a similar behaviour might be possible.
>
> Read some of the replies, some very good suggestions were given.
>
>> ... And there's a difference?
>
> Yes there is. Sorry if you don't know the difference.
>
>>
>> "I need to know how much time has elapsed since I set a timer,
>> because<problem
>> description here>" and the answers are much easier to give.
>
> Maybe with the school projects you work with.
>
> Have a good week-end.
>
> Simon


From: Joseph M. Newcomer on
In writing device drivers, we typically use the IoStartTimer method which starts a
1-second timer. In this model, the way a timer is "paused" is to simply set a flag that
says "ignore the timer event"; and the way to get a 10-second timeout is to increment a
variable and take an action when it hits 10. To "reset" the timer, the variable is set to
0.
joe

On Fri, 30 Apr 2010 09:10:39 -0500, "Tom Serface" <tom(a)camaswood.com> wrote:

>
>You could simulate a pause by just keeping track of the timer tick downs
>(seconds) in your own variable and decrement it every time the timer is
>called. Then to pause, you would essentially stop the timer, but keep the
>variable (a member of your class). Then to start you would use the amount
>of time not ticked off (using the variable) to set the timer again.
>
>When the timer finishes you could you stop and start it again using the full
>amount of time again as part of the timer handler.
>
>You could also have a flag, like your busy flag, that just ignores the
>timer firing when it happens and returns immediately without doing anything.
>This would simulate doing a pause (at least in the functionality of it).
>
>Tom
>
>"Simon" <bad(a)example.com> wrote in message
>news:eUH0kcG6KHA.4508(a)TK2MSFTNGP06.phx.gbl...
>> On 2010/04/30 02:48 PM, Tom Serface wrote:
>>> Hi Simon,
>>>
>>> Did you get an answer that works for you? I want to make sure your
>>> problem got solved.
>>>
>>
>> Hi,
>>
>> Thanks for the reply, in the end I just added a flag that does something
>> like.
>>
>> // -----------------------------
>> OnTimer( ... )
>> {
>> if( busy )
>> {
>> timer_is_complete = true;
>> }
>> else
>> {
>> DoSomething();
>> }
>> }
>>
>> ...
>>
>> DoingSomStuff()
>> {
>> // do the stuff
>>
>> if( true == timer_is_comlete )
>> {
>> DoSomething();
>> }
>> }
>>
>> // --------------------------------
>>
>> But I am not 100% happy with it. I would prefer to pause the timer. That
>> way, when you resume the timer the normal chain of events will happen.
>>
>> I could write my own timer class using a thread but this would add a lot
>> over testing overhead to the current app.
>> I will almost certainly create a branch with a bunch of tests before going
>> live with it.
>>
>> Thanks again
>>
>> 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: Doug Harrison [MVP] on
On Fri, 30 Apr 2010 17:35:24 +0200, Simon <bad(a)example.com> wrote:

>> And you should not compare a bool variable to a bool literal; this is poor style. What
>> value to you think a bool variable has? And why aren't you just saying
>
>This is your style, I don't agree with it.

It's not just bad style, it's bad practice. When you compare to the bool
literal "true", the other side of the expression had better well be an
actual bool variable. Otherwise, if it's non-zero but not exactly equal to
1, then the test "x == true" will fail for the non-bool x, even though any
non-zero value is considered true in C++ and C. In Windows and MFC
programming, you will frequently deal with BOOL, a typedef for int, for
which it is an unequivocal blunder to compare to TRUE. Making special
exceptions for the C++ bool type just introduces complexity for no reason
at all, and FWIW, I don't know anyone who does it. All I see and use for
bools is x and !x.

--
Doug Harrison
Visual C++ MVP
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: _in s and _out s ?
Next: MSI Serial Number Validation