SharpLibEar/ActionSleep.cs
author StephaneLenclud
Wed, 31 Aug 2016 20:20:32 +0200
changeset 265 82e87f4956ea
parent 263 3ab73a2a72d8
permissions -rw-r--r--
Actions can now have children.
     1 //
     2 
     3 
     4 using System.Runtime.Serialization;
     5 using System.Threading;
     6 using System.Threading.Tasks;
     7 
     8 namespace SharpLib.Ear
     9 {
    10     
    11 
    12     [DataContract]
    13     [AttributeObject(Id = "Thread.Sleep", Name = "Sleep", Description = "Have the current thread sleep for the specified amount of milliseconds.")]
    14     public class ActionSleep : Action
    15     {
    16         [DataMember]
    17         [AttributeObjectProperty
    18             (
    19                 Id = "Thread.Sleep.Timeout",
    20                 Name = "Timeout (ms)",
    21                 Description = "Specifies the number of milliseconds this action will sleep for.",
    22                 Minimum = "0",
    23                 Maximum = "60000",
    24                 Increment =  "1000"
    25             )
    26         ]
    27         public int TimeoutInMilliseconds { get; set; }
    28 
    29         public ActionSleep()
    30         {
    31             TimeoutInMilliseconds = 1000;
    32         }
    33 
    34 
    35         public ActionSleep(int aMillisecondsTimeout)
    36         {
    37             TimeoutInMilliseconds = aMillisecondsTimeout;
    38         }
    39 
    40         public override string BriefBase()
    41         {
    42             return AttributeName + " for " + TimeoutInMilliseconds + " ms";
    43         }
    44 
    45 
    46         protected override async Task DoExecute()
    47         {
    48             await Task.Delay(TimeoutInMilliseconds);
    49         }
    50 
    51     }
    52 
    53 
    54 
    55 }