##// END OF EJS Templates
removed the reference to the parent from the promise object this allows...
removed the reference to the parent from the promise object this allows resolved promises to release parents and results they are holding. Added complete set of operations to IPromiseBase interface Subscribing to the cancellation event of the promise should not affect it's IsExclusive property More tests.

File last commit:

r6:dfa21d507bc5 default
r33:b255e4aeef17 default
Show More
Animation.cs
97 lines | 2.5 KiB | text/x-csharp | CSharpLexer
cin
Added Impl.Fx
r3 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
cin
Implab.Fx: implemented animation object...
r4 using System.Timers;
using System.ComponentModel;
using System.Diagnostics;
cin
Added Impl.Fx
r3
namespace Implab.Fx
{
cin
Implab.Fx: implemented animation object...
r4 public delegate void AnimationStep<T>(T target, int elapsed, int duration);
public class Animation<TArg> where TArg: class
cin
Added Impl.Fx
r3 {
int m_duration;
cin
Implab.Fx: implemented animation object...
r4 int m_delay;
int m_elapsed;
int m_prevTicks;
TArg m_arg;
ISynchronizeInvoke m_syncronizationObject;
public event AnimationStep<TArg> Step;
Promise<TArg> m_promise;
public Animation(TArg target, int duration, int delay)
{
if (duration <= 0)
throw new ArgumentOutOfRangeException("duration");
if (delay <= 0)
throw new ArgumentOutOfRangeException("delay");
m_arg = target;
m_syncronizationObject = target as ISynchronizeInvoke;
m_duration = duration;
m_delay = delay;
m_promise = new Promise<TArg>();
}
public Animation(TArg target)
: this(target, 500, 30)
{
}
public TArg Traget
{
get { return m_arg; }
}
cin
Added Impl.Fx
r3
cin
Implab.Fx: implemented animation object...
r4 public Promise<TArg> Play()
{
var timer = new Timer(m_delay);
cin
*refactoring: Promise.Then now returns a new chained promise...
r6 timer.AutoReset = false;
cin
Implab.Fx: implemented animation object...
r4 timer.SynchronizingObject = m_syncronizationObject;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
cin
Added Impl.Fx
r3
cin
Implab.Fx: implemented animation object...
r4 m_prevTicks = Environment.TickCount;
timer.Start();
return m_promise;
}
void timer_Elapsed(object sender, ElapsedEventArgs args)
{
var timer = sender as Timer;
var dt = Environment.TickCount - m_prevTicks;
m_prevTicks = Environment.TickCount;
m_elapsed += dt;
if (m_elapsed > m_duration)
m_elapsed = m_duration;
try
{
var handler = Step;
if (handler != null)
handler(m_arg, m_elapsed, m_duration);
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
}
if (m_elapsed < m_duration)
timer.Start();
else
{
timer.Dispose();
m_promise.Resolve(m_arg);
}
}
cin
Added Impl.Fx
r3 }
}