Animated Controls

N

NickP

Hi there,

I've made a few animated controls but would like to check on the correct
procedure for doing so as unfortunately every now and then, without warning,
I recieve a GDI+ Exception stating that the graphics object is kin use
elsewhere.

Basically my user control has the following styles set,
AllPaintingInWmPaint and UserPaint. When my control recieves a string array
it starts scrolling each string in the array in a marquee fashion. I have a
stop function which I use to be able to stop the animation when changing the
list.

All of my drawing is performed in a separate thread as it is a constant
loop and I do not want to lock the controls thread. The thread is
synchronised using manual reset events and is impossible to enter twice.
The stop function is also synchronised and will lock the calling thread
until the animation is completely stopped.

The graphics object that the exception is occuring on is SyncLock'ed
every time it is used and is only declared for the life time of the
function, yet I am informed every now and then that it is in use elsewhere,
I can't see that this is the case.

Of course, I could drop down to GDI and eliminate this problem all
together but I would rather just re-implement my code so that it is done
*correctly*

I have tried alternative methods of running an FPS based animation loop
within a control before but this requires that drawing be performed within
the Paint event, which obviously has an impact in performance on the
controls thread, I did not like doing this in an application as it was too
heavy.

Have any of you got any suggestions as to how I can either fix this
problem I am getting, or implement an animated control in a different way
that would provide rock solid performance.

Thanks a million in advance!

Nick.
 
N

NickP

Typical! After stressing over this for ages I found the true cause of the
issue! My method used to stop the animation was no syncrhonised so at one
point it was being used twice at once. I have now synchronised the method
by using a manual reset event which is rest upon exit of the function, if on
the rare chance 2 threads come in at once, only 1 will get through and has
to wait for the other to finish, hurrah!

So I guess my question is pretty dedundant now unless anyone else is
experiencing similar issues :)

Nick.
 

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