Re: Multiple Timers
From: AliR (AliR_at_newsgroup.nospam)
Date: 01/10/05
- Next message: Lisa Pearlson: "Re: class wizard / conditional compilation"
- Previous message: Ajay Kalra: "Re: class wizard / conditional compilation"
- In reply to: Vince: "Multiple Timers"
- Next in thread: Vince: "Re: Multiple Timers"
- Reply: Vince: "Re: Multiple Timers"
- Messages sorted by: [ date ] [ thread ]
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 ?
>
>
>
>
>
- Next message: Lisa Pearlson: "Re: class wizard / conditional compilation"
- Previous message: Ajay Kalra: "Re: class wizard / conditional compilation"
- In reply to: Vince: "Multiple Timers"
- Next in thread: Vince: "Re: Multiple Timers"
- Reply: Vince: "Re: Multiple Timers"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|