SharpLibEar/ActionDelay.cs
changeset 263 3ab73a2a72d8
child 264 4a08e1b7ba64
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/SharpLibEar/ActionDelay.cs	Wed Aug 31 16:24:33 2016 +0200
     1.3 @@ -0,0 +1,53 @@
     1.4 +//
     1.5 +
     1.6 +
     1.7 +using System.Runtime.Serialization;
     1.8 +using System.Threading;
     1.9 +using System.Threading.Tasks;
    1.10 +
    1.11 +namespace SharpLib.Ear
    1.12 +{
    1.13 +    [DataContract]
    1.14 +    [AttributeObject(Id = "Task.Delay", Name = "Delay", Description = "Delay the execution of the next task by the specified amount of milliseconds.")]
    1.15 +    public class ActionDelay : Action
    1.16 +    {
    1.17 +        [DataMember]
    1.18 +        [AttributeObjectProperty
    1.19 +            (
    1.20 +                Id = "Task.Delay.Milliseconds",
    1.21 +                Name = "Delay (ms)",
    1.22 +                Description = "Specifies our delay in milliseconds.",
    1.23 +                Minimum = "0",
    1.24 +                Maximum = "60000",
    1.25 +                Increment = "1000"
    1.26 +            )
    1.27 +        ]
    1.28 +        public int Milliseconds { get; set; }
    1.29 +
    1.30 +        public ActionDelay()
    1.31 +        {
    1.32 +            Milliseconds = 1000;
    1.33 +        }
    1.34 +
    1.35 +
    1.36 +        public ActionDelay(int aMillisecondsTimeout)
    1.37 +        {
    1.38 +            Milliseconds = aMillisecondsTimeout;
    1.39 +        }
    1.40 +
    1.41 +        public override string Brief()
    1.42 +        {
    1.43 +            return AttributeName + " for " + Milliseconds/1000.0 + " seconds";
    1.44 +        }
    1.45 +
    1.46 +
    1.47 +        protected override async Task DoExecute()
    1.48 +        {
    1.49 +            await Task.Delay(Milliseconds);
    1.50 +        }
    1.51 +
    1.52 +    }
    1.53 +
    1.54 +
    1.55 +
    1.56 +}
    1.57 \ No newline at end of file