Re: Multiple Timers

From: AliR (AliR_at_newsgroup.nospam)
Date: 01/10/05


Date: Mon, 10 Jan 2005 21:45:38 GMT

You concern in B is the main concern. While you are doing something in your
OnTimer no other messages will be received by your window, including
WM_TIMER messages, unless you put a message loop in the middle of your code.
But if you really want to be safe, you should use two threads. The only
problem here would be synchronizing data access if they are using the same
data. Use a mutex to synchronizing data access if they are using the same
data.

AliR.

"Vince" <biproc2004@yahoo.fr> wrote in message
news:41e2d6a8$0$29913$636a15ce@news.free.fr...
> Hello,
>
> I was wondering if using standard MFC timers are good enough for what I
> want to do.
> Usually I only use one timer at the same time but in the application I am
> currently writing (dialog-based) I need two timers.
> My application loads a xml file like below and display some messages in
> function of current time. The xml file fills an array of struct (Lets'
call
> it arrPlanning)
>
> <BornePlanning>
> <Day value="241104">
> <Time value="06:00-08:29">
> <SearchCard>1</SearchCard>
> <Label id="1">I display Label1</Label>
> <Label id="2">I display Label2</Label>
> <Label id="3">lI display Label3</Label>
> <Label id="4">ZEAEAZEAZAZE</Label>
> <Label id="5">?NNVVBVBBN</Label>
> <Label id="6">?NNVVBVBBN</Label>
> </Time>
> <Time value="09:00-12:29">
> <SearchCard>0</SearchCard>
> <Label id="1">Label 1</Label>
> <Label id="2">Label 2</Label>
> <Label id="3">Label 3</Label>
> <Label id="4">Label 4</Label>
> <Label id="5">Label 5</Label>
> <Label id="6">?NNVVBVBBN</Label>
> </Time>
> </Day>
>
> So basically I have 2 timers
> 1 - Timer that parse an array (arrPlanning) to find what message has to be
> displayed- every 1s
> 2 - Timer that communicate with a device every 600ms and display a
message.
>
>
> So my first idea was to do something like this :
>
> void CMyDlg::OnInitDialog
> {
> SetTimer(IDT_PLANNING_TIMER, 1000, NULL);
> SetTimer(IDT_DEVICE_TIMER, 600, NULL);
> }
> and to handle different timer in
> void CMyDlg::OnTimer(UINT nIDEvent)
> {
> if ( nIDEvent == IDT_PLANNING_TIMER)
> xxxxxx;// Find current message to display
> if ( nIDEvent == IDT_DEVICE_TIMER)
> yyyyy;// Communicate with a device and display its response
> }
>
>
> A) But my question is : is it a good idea or should I use thread instead
or
> something else ?
>
>
> B) And By the way what happens if the instructions your doing in the
OnTimer
> takes more time than the resolution ?
>
>
>
>
>



Relevant Pages

  • Re: Multiple Timers
    ... > OnTimer no other messages will be received by your window, ... Use a mutex to synchronizing data access if they are using the same ... >> I was wondering if using standard MFC timers are good enough for what I ... The xml file fills an array of struct (Lets' ...
    (microsoft.public.vc.mfc)
  • Re: [Tk] Double, Triple, Quadruple,
    ... But window system managers have their own settings about the time between two ... For mouse clicks, you do have timers, but only for the Double- etc ... distributed through the X resource system using the "multiClickTime" ... but does not act on multiClickTime. ...
    (comp.lang.tcl)
  • Re: Question on CDialog and OnInitDialog
    ... The window will be drawn ... Timers are less certain. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: application question
    ... I have a application im placing in the system tray... ... this is a dialog window with some schedules on it, ... when the application starts, i want to show the window, but then reset the ... timers and set the window to the system tray ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: SetTimer with nIDEvent = 0
    ... > However I have mistakenly set nIDEvent = 0 on many occasions with no ... SetTimer ignores nIDEvent for timers that aren't attached to ... whoever called RegisterClass for the window type. ... but be aware that some window types use timers for their own purposes. ...
    (microsoft.public.vc.mfc)

Loading