Timer AutoResetEvent Animation...
-
I want to make a animation that moves from a position value using Timer and AutoResetEvent... I implemented it like this... AutoResetEvent are; private void StartMovie() { ptimer=new System.Windows.Forms.Timer(); ptimer.Interval=10; ptimer.Tick += new EventHandler(pTimerOnTick); ptimer.Start(); } private void pTimerOnTick(object sender, EventArgs e) { if(movingK<=605&&isMoving)//till movkingK(pos_X)<605 show it's moving. { are.Set(); movingK+=10; Invalidate(); are.ReSet(); are.WaitOne(); } else { are.Set(); StonePut(b_intStone,intValueTemp,b_selectedStone,selectValueTemp,First,0); ptimer.Stop(); ptimer.Tick-=new EventHandler(pTimerOnTick); isMoving=false; } } private void DThis1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { rectDst=new Rectangle(movingK,movingKY,54,60); grfx.DrawImage(GeneralsImage,rectDst,rectSrc,GraphicsUnit.Pixel); //paint rutine has no problem... } actually I did not understand well AutoResetEvent and how to it wait event and go next job... I think if it needs a loop then it goes more complex. please someone help me and show me a good implementation of this problem. Image will remind us some feelings and if I can ask someone about a problem, that's not a bad life.
-
I want to make a animation that moves from a position value using Timer and AutoResetEvent... I implemented it like this... AutoResetEvent are; private void StartMovie() { ptimer=new System.Windows.Forms.Timer(); ptimer.Interval=10; ptimer.Tick += new EventHandler(pTimerOnTick); ptimer.Start(); } private void pTimerOnTick(object sender, EventArgs e) { if(movingK<=605&&isMoving)//till movkingK(pos_X)<605 show it's moving. { are.Set(); movingK+=10; Invalidate(); are.ReSet(); are.WaitOne(); } else { are.Set(); StonePut(b_intStone,intValueTemp,b_selectedStone,selectValueTemp,First,0); ptimer.Stop(); ptimer.Tick-=new EventHandler(pTimerOnTick); isMoving=false; } } private void DThis1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { rectDst=new Rectangle(movingK,movingKY,54,60); grfx.DrawImage(GeneralsImage,rectDst,rectSrc,GraphicsUnit.Pixel); //paint rutine has no problem... } actually I did not understand well AutoResetEvent and how to it wait event and go next job... I think if it needs a loop then it goes more complex. please someone help me and show me a good implementation of this problem. Image will remind us some feelings and if I can ask someone about a problem, that's not a bad life.
Hi i don't understand your problem well . if you want to create an animation by showing a picture in every constant time it would be like this :
private void StartMovie() { ptimer=new System.Windows.Forms.Timer(); ptimer.Interval=10; ptimer.Tick += new EventHandler(pTimerOnTick); ptime.AutoReset = true ; ptimer.Start(); } private void pTimerOnTick(object sender, EventArgs e) { if(movingK<=605&&isMoving)//till movkingK(pos_X)<605 show it's moving. { are.Set(); movingK+=10; Invalidate(); are.ReSet(); are.WaitOne(); } }
in onpaint event draw any picture that must be shown to create an animation. why you create a new tick event handler inpTimerOnTick
in else block ? do you want to simulate the autoreset ? Amir Jalaly -
I want to make a animation that moves from a position value using Timer and AutoResetEvent... I implemented it like this... AutoResetEvent are; private void StartMovie() { ptimer=new System.Windows.Forms.Timer(); ptimer.Interval=10; ptimer.Tick += new EventHandler(pTimerOnTick); ptimer.Start(); } private void pTimerOnTick(object sender, EventArgs e) { if(movingK<=605&&isMoving)//till movkingK(pos_X)<605 show it's moving. { are.Set(); movingK+=10; Invalidate(); are.ReSet(); are.WaitOne(); } else { are.Set(); StonePut(b_intStone,intValueTemp,b_selectedStone,selectValueTemp,First,0); ptimer.Stop(); ptimer.Tick-=new EventHandler(pTimerOnTick); isMoving=false; } } private void DThis1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { rectDst=new Rectangle(movingK,movingKY,54,60); grfx.DrawImage(GeneralsImage,rectDst,rectSrc,GraphicsUnit.Pixel); //paint rutine has no problem... } actually I did not understand well AutoResetEvent and how to it wait event and go next job... I think if it needs a loop then it goes more complex. please someone help me and show me a good implementation of this problem. Image will remind us some feelings and if I can ask someone about a problem, that's not a bad life.
I don't see any reason for you to use an AutoResetEvent. As far as I can see, pTimerOnTick is called by only one thread (the UI thread), so you don't need any synchronization mechanism at all. Regards Senthil _____________________________ My Blog | My Articles | WinMacro