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