As for the software project I'm working on now .
I have the following methods that basically move the canvas using a timer:
DispatcherTimer dt = new DispatcherTimer();
public void Ahead(int pix)
{
var movx = 0;
var movy = 0;
dt.Interval = TimeSpan.FromMilliseconds(5);
dt.Tick += new EventHandler((object sender, EventArgs e) =>
{
if (movx >= pix || movy >= pix)
{
dt.Stop();
return;
}
Bot.Body.RenderTransform = new TranslateTransform(movx++, movy++);
});
dt.Start();
}
public void TurnLeft(double deg)
{
var currAngle = 0;
dt.Interval = TimeSpan.FromMilliseconds(5);
dt.Tick += new EventHandler(delegate(object sender, EventArgs e)
{
if (currAngle <= (deg - (deg * 2)))
{
dt.Stop();
}
Bot.Body.RenderTransform = new RotateTransform(currAngle--, BodyCenter.X, BodyCenter.Y);
});
dt.Start();
}
Now, from another library, these methods are called like this:
public void run()
{
Ahead(200);
TurnLeft(90);
}
Now, of course, I want these animations to happen after another, but what happens is that the event handler is dt.Tick DispatchTimeroverwritten when the second method (in this case TurnLeft(90)) is called, and thus only the second method is executed.
I need to create some kind of queue that will allow me to press pop methods in this queue so that the dt(timer DispatchTimer) executes them one by one ... in the order in which they are in the 'queue'
? , ?