Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Timer AutoResetEvent Animation...

Timer AutoResetEvent Animation...

Scheduled Pinned Locked Moved C#
helptutorialcareer
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arbrsoft
    wrote on last edited by
    #1

    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.

    A S 2 Replies Last reply
    0
    • A arbrsoft

      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.

      A Offline
      A Offline
      Amir Jalaly
      wrote on last edited by
      #2

      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 in pTimerOnTick in else block ? do you want to simulate the autoreset ? Amir Jalaly

      1 Reply Last reply
      0
      • A arbrsoft

        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.

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups