problems with drawing threads

Hello,

To simplify my problem i want to write aplication which draws in thread every 3 seconds new reactangle, code below

int myThreads(void)
{
int i = 0;
int j = 0;
int color = 0;

while(1)
{
	PtEnter(0);
	 if (color == 1)
	 {
		 PgSetFillColor(Pg_BLACK);
		 color = 0;
	 }
	else
	{
		PgSetFillColor(Pg_BLUE);
		color = 1;
	}
	PgDrawIRect(i, i, i+5, i+5, Pg_DRAW_FILL);
	PtLeave(0);
	i = i + 5;
	sleep(1);
}
return 0;

}

I made plain applciacation in appBuilder. It works fine only when i move mouse from plain outside and again inside. Otherwise reactangels arent drawn only when i get back with my mouse courser back to the plain :frowning: And then stops again, whne i get with the mouse coursor outside, there is refrech and stops again :frowning:
Have you got any hints for me ?