SharpLibEar/ActionDelay.cs
author Stephane Lenclud
Fri, 02 Sep 2016 01:38:08 +0200
changeset 267 a601b377a3eb
parent 264 4a08e1b7ba64
permissions -rw-r--r--
Event trigger by name now won't trigger disabled events.
StephaneLenclud@263
     1
//
StephaneLenclud@263
     2
StephaneLenclud@263
     3
StephaneLenclud@263
     4
using System.Runtime.Serialization;
StephaneLenclud@263
     5
using System.Threading;
StephaneLenclud@263
     6
using System.Threading.Tasks;
StephaneLenclud@263
     7
StephaneLenclud@263
     8
namespace SharpLib.Ear
StephaneLenclud@263
     9
{
StephaneLenclud@263
    10
    [DataContract]
StephaneLenclud@265
    11
    [AttributeObject(Id = "Action.Task.Delay", Name = "Delay", Description = "Delay the execution of the next task.")]
StephaneLenclud@263
    12
    public class ActionDelay : Action
StephaneLenclud@263
    13
    {
StephaneLenclud@263
    14
        [DataMember]
StephaneLenclud@263
    15
        [AttributeObjectProperty
StephaneLenclud@263
    16
            (
StephaneLenclud@263
    17
                Id = "Task.Delay.Milliseconds",
StephaneLenclud@263
    18
                Name = "Delay (ms)",
StephaneLenclud@265
    19
                Description = "Specifies the delay in milliseconds.",
StephaneLenclud@263
    20
                Minimum = "0",
StephaneLenclud@263
    21
                Maximum = "60000",
StephaneLenclud@263
    22
                Increment = "1000"
StephaneLenclud@263
    23
            )
StephaneLenclud@263
    24
        ]
StephaneLenclud@263
    25
        public int Milliseconds { get; set; }
StephaneLenclud@263
    26
StephaneLenclud@263
    27
        public ActionDelay()
StephaneLenclud@263
    28
        {
StephaneLenclud@263
    29
            Milliseconds = 1000;
StephaneLenclud@263
    30
        }
StephaneLenclud@263
    31
StephaneLenclud@263
    32
StephaneLenclud@263
    33
        public ActionDelay(int aMillisecondsTimeout)
StephaneLenclud@263
    34
        {
StephaneLenclud@263
    35
            Milliseconds = aMillisecondsTimeout;
StephaneLenclud@263
    36
        }
StephaneLenclud@263
    37
StephaneLenclud@264
    38
        public override string BriefBase()
StephaneLenclud@263
    39
        {
StephaneLenclud@263
    40
            return AttributeName + " for " + Milliseconds/1000.0 + " seconds";
StephaneLenclud@263
    41
        }
StephaneLenclud@263
    42
StephaneLenclud@263
    43
StephaneLenclud@263
    44
        protected override async Task DoExecute()
StephaneLenclud@263
    45
        {
StephaneLenclud@263
    46
            await Task.Delay(Milliseconds);
StephaneLenclud@263
    47
        }
StephaneLenclud@263
    48
StephaneLenclud@263
    49
    }
StephaneLenclud@263
    50
StephaneLenclud@263
    51
StephaneLenclud@263
    52
StephaneLenclud@263
    53
}