I'm a little confused about how your scrolling works, but I think the code below can give you a decent starting point on how to fix this problem.
As stated in the comments section, you constantly rotate in a loop and update the image as quickly as possible (if I understand your code correctly):
void refresh_visible() { while( threadsAlive ) { while( scrolling ) { ShowCurrent(); } } } void refresh_hidden() { while( threadsAlive ) { while( scrolling ) { hideInvisibleImages(); } } }
It seems nice to have an appropriate refresh rate, regardless of scrolling. You must implement an update rate that is somewhere between 24 and 30 frames per second.
Something like this might be ok:
using System.Threading; class YourClass { // Tick every 42 millisecond or about 24 times per second private readonly int _refreshRate = 42; private volatile bool _scrolling; private Timer _timer; YourClass() { _timer = new Timer(TimerTick, null, 0, _refreshRate); } public void TimerTick(object state) { if (_scrolling) { ShowCurrent(); HideInvisibleImages(); } } void ShowCurrent() { //... } void HideInvisibleImages() { //... } }
Note that if you create and destroy many instances of YourClass , you must also get rid of the Timer object when you are done with it. The Timer delegate will contain a reference to an instance of YourClass , and this will prevent garbage collection.
Kiril source share