Timer Tick in compact framework

P

Patrick Dugan

I am experimenting with some graphics using vb.net/compact framework. I
have a Timer which is supposed to fire every 100 milliseconds to update a
graphic. When the application runs (in either the runtime as a emulator or
on the actual PDA) the graphics only update once per second. Is there some
limitation to the timer? The timer shows the interval as being 100 yet the
graphics do not update that fast. They do update exactly once each second.
There is little actually going on for this animation (drawing a couple of
lines) Is there some way to get the event to fire more rapidly?
 
G

Guest

In your time, call Application.DoEvents to force the redraw event from within
your timer.

Regards,
Rick D.
Contractor
 
P

Patrick Dugan

No effect. Still only updates once per second. Guess I just have to live
with it.
 
G

Guest

You shouldn't have to. You must have something incorrect in your code, as
it will definitely run faster than 1s. The OS scheduler tick is 1ms, so
100ms is very easy to achieve, ever for a Forms timer.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
 
H

Hilton

At the beginning of your Paint method (whatever you called it), get the
time, at the end get the time, write the difference to a file. Report back.

Something like:
DateTime dt0 = DateTime.Now;
paint here
DateTime dt1 = DateTime.Now;

using (StreamWriter sw = new StreamWriter ("times.txt", true))
{
sw.WriteLine ((dt1-dt0).TotalSeconds.ToString ("F3");
}

Look for the file "times.txt" in the root directory of the device.

Hilton
 
P

Patrick Dugan

Well the log file shows the painting is occuring many times per second, but
the screen itself is only once per second. I have a PaintBox1.refresh at
each paint event (otherwise nothing shows) but the update appears to be only
once per second. It must be in the code that calculates the location of the
line. It works fine on a PC with the same code but not on the PPC.

This is the code in question...

Dim canvas As Graphics
canvas = Graphics.FromImage(PictureBox1.Image)
Dim HPen As New Pen(Color.White, 1)
Dim HPenT As New Pen(Color.White, 2)

Dim CX As Integer = PictureBox1.Image.Width \ 2
Dim CY As Integer = PictureBox1.Image.Height \ 2

Dim VS As Double = (Now.Second + (Now.Millisecond / 1000)) / 60.0 * 2 *
PI
Dim RS As Integer = (PictureBox1.Image.Width \ 3) + 12

Dim intNewX As Integer = CX + Round(RS * Sin(VS))
Dim intNewY As Integer = CY - Round(RS * Cos(VS))

Dim intNewXT As Integer = CX - Round((RS / 4) * Sin(VS))
Dim intNewYT As Integer = CY + Round((RS / 4) * Cos(VS))

canvas.DrawLine(HPen, 120, 120, intNewX, intNewY)
canvas.DrawLine(HPenT, 120, 120, intNewXT, intNewYT)
canvas.Dispose()

PictureBox1.Refresh()


This is supposed to draw a line representing a second hand on the screen.
On the PC the second hand is quite smooth but on the PPC it jumps from
second to second.
I determined that the "Now.Millsecond" only returns zero each time. Do PPCS
not show millseconds? I did the log for Now.Milliseconds.ToString and it
was zero every time. That explains the update not happening as often as
expected but how can you get millseconds?
 
P

Patrick Dugan

Thanks! I ended up finding out about the millseconds no longer being used
in CF. I made a somewhat crude version of the code you
referenced (in vb.net visual basic) and it seems to work fine.
 
G

Guest

To be clear, it's not that the milliseconds aren't "used" by the CF, it's
simply that the OS is not correctly reporting them on your specific
platform. The CF is only reporting what the OS gives it. If you had
hardware that filled in the ms field for GetLocalTime (which is the API that
all time values come from) then it would be right in DateTime.Now.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top