Timer-based Animation with g.DrawImage Gives Random Pauses

M

mcm

For my Windows CE 5.0 App (using C# in Visual Studio 2005) I have to create several images (on the fly) and play them back as an animation.

I've created an "Animation Control" which holds an array of images (usually about 18 images) and uses a timer to show them via "DrawImage".
This control loops through the array of images on each counter tick per the following:

private void timerAnimation_Tick(object sender, EventArgs e)
{
if (animationImages.Length <= 0) // no images in the array
return;
if (++nCurrentImageRef >= animationImages.Length)
nCurrentImageRef = 0;

// draw the current image
// gControl is the Graphics object for this control
gControl.DrawImage(animationImages[nCurrentImageRef], ClientRectangle.Left, ClientRectangle.Top);

}

My problem is that this animation runs smoothly for a couple hundred timer ticks, pauses for a few seconds and then continues where it left off.
These pauses are typically for 3 or 4 seconds and they occur somewhat randomly. Is this due to garbage collection or due to my "DrawImage" approach?

I've used other timers in this application (just to test what's going on) and they don't experience these same "pauses" - just this one.

Thanks.
 
C

Chris Tacke, MVP

It's highly likely to be a GC issue, though RPM would tell you for certain
(and quite quickly). We don't see enough of your code to know where any GC
issues might lie though.

-Chris
 
M

mcm

OK - you've piqued my interest... what's RPM?


It's highly likely to be a GC issue, though RPM would tell you for certain
(and quite quickly). We don't see enough of your code to know where any GC
issues might lie though.

-Chris


mcm said:
For my Windows CE 5.0 App (using C# in Visual Studio 2005) I have to
create several images (on the fly) and play them back as an animation.

I've created an "Animation Control" which holds an array of images
(usually about 18 images) and uses a timer to show them via "DrawImage".
This control loops through the array of images on each counter tick per
the following:

private void timerAnimation_Tick(object sender, EventArgs e)
{
if (animationImages.Length <= 0) // no images in the array
return;
if (++nCurrentImageRef >= animationImages.Length)
nCurrentImageRef = 0;

// draw the current image
// gControl is the Graphics object for this control
gControl.DrawImage(animationImages[nCurrentImageRef],
ClientRectangle.Left, ClientRectangle.Top);

}

My problem is that this animation runs smoothly for a couple hundred timer
ticks, pauses for a few seconds and then continues where it left off.
These pauses are typically for 3 or 4 seconds and they occur somewhat
randomly. Is this due to garbage collection or due to my "DrawImage"
approach?

I've used other timers in this application (just to test what's going on)
and they don't experience these same "pauses" - just this one.

Thanks.
 
M

mcm

Never mind - I found it.

OK - you've piqued my interest... what's RPM?


It's highly likely to be a GC issue, though RPM would tell you for certain
(and quite quickly). We don't see enough of your code to know where any GC
issues might lie though.

-Chris


mcm said:
For my Windows CE 5.0 App (using C# in Visual Studio 2005) I have to
create several images (on the fly) and play them back as an animation.

I've created an "Animation Control" which holds an array of images
(usually about 18 images) and uses a timer to show them via "DrawImage".
This control loops through the array of images on each counter tick per
the following:

private void timerAnimation_Tick(object sender, EventArgs e)
{
if (animationImages.Length <= 0) // no images in the array
return;
if (++nCurrentImageRef >= animationImages.Length)
nCurrentImageRef = 0;

// draw the current image
// gControl is the Graphics object for this control
gControl.DrawImage(animationImages[nCurrentImageRef],
ClientRectangle.Left, ClientRectangle.Top);

}

My problem is that this animation runs smoothly for a couple hundred timer
ticks, pauses for a few seconds and then continues where it left off.
These pauses are typically for 3 or 4 seconds and they occur somewhat
randomly. Is this due to garbage collection or due to my "DrawImage"
approach?

I've used other timers in this application (just to test what's going on)
and they don't experience these same "pauses" - just this one.

Thanks.
 
M

mcm

RPM showed the GC counts incrementing occaisionally, however these occurrences didn't ever correspond to delays in the application's animation.
The GC count would go up by one, while the animation was running smoothly. When the animation paused, nothing unusual was occurring in RPM.

I'm still puzzled.


It's highly likely to be a GC issue, though RPM would tell you for certain
(and quite quickly). We don't see enough of your code to know where any GC
issues might lie though.

-Chris


mcm said:
For my Windows CE 5.0 App (using C# in Visual Studio 2005) I have to
create several images (on the fly) and play them back as an animation.

I've created an "Animation Control" which holds an array of images
(usually about 18 images) and uses a timer to show them via "DrawImage".
This control loops through the array of images on each counter tick per
the following:

private void timerAnimation_Tick(object sender, EventArgs e)
{
if (animationImages.Length <= 0) // no images in the array
return;
if (++nCurrentImageRef >= animationImages.Length)
nCurrentImageRef = 0;

// draw the current image
// gControl is the Graphics object for this control
gControl.DrawImage(animationImages[nCurrentImageRef],
ClientRectangle.Left, ClientRectangle.Top);

}

My problem is that this animation runs smoothly for a couple hundred timer
ticks, pauses for a few seconds and then continues where it left off.
These pauses are typically for 3 or 4 seconds and they occur somewhat
randomly. Is this due to garbage collection or due to my "DrawImage"
approach?

I've used other timers in this application (just to test what's going on)
and they don't experience these same "pauses" - just this one.

Thanks.
 
C

Chris Tacke, MVP

We don't know enough about what's happening in the app to make any
diagnosis. I'd guess a timer firing and eating up resources. If that's not
it then I'd look at kernel tracker and see who's eating quantum.

-Chris


mcm said:
RPM showed the GC counts incrementing occaisionally, however these
occurrences didn't ever correspond to delays in the application's
animation.
The GC count would go up by one, while the animation was running smoothly.
When the animation paused, nothing unusual was occurring in RPM.

I'm still puzzled.


It's highly likely to be a GC issue, though RPM would tell you for certain
(and quite quickly). We don't see enough of your code to know where any
GC
issues might lie though.

-Chris


mcm said:
For my Windows CE 5.0 App (using C# in Visual Studio 2005) I have to
create several images (on the fly) and play them back as an animation.

I've created an "Animation Control" which holds an array of images
(usually about 18 images) and uses a timer to show them via "DrawImage".
This control loops through the array of images on each counter tick per
the following:

private void timerAnimation_Tick(object sender, EventArgs e)
{
if (animationImages.Length <= 0) // no images in the array
return;
if (++nCurrentImageRef >= animationImages.Length)
nCurrentImageRef = 0;

// draw the current image
// gControl is the Graphics object for this control
gControl.DrawImage(animationImages[nCurrentImageRef],
ClientRectangle.Left, ClientRectangle.Top);

}

My problem is that this animation runs smoothly for a couple hundred
timer
ticks, pauses for a few seconds and then continues where it left off.
These pauses are typically for 3 or 4 seconds and they occur somewhat
randomly. Is this due to garbage collection or due to my "DrawImage"
approach?

I've used other timers in this application (just to test what's going
on)
and they don't experience these same "pauses" - just this one.

Thanks.
 

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