SharpLibEar/ActionSleep.cs
author StephaneLenclud
Fri, 12 Aug 2016 20:25:05 +0200
changeset 231 4c706feaf706
parent 228 6a84d8282226
child 258 e237c2e33545
permissions -rw-r--r--
Events can now be instantiated.
Action editor is now a generic object editor.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System.Runtime.Serialization;
StephaneLenclud@210
     5
using System.Threading;
StephaneLenclud@210
     6
StephaneLenclud@210
     7
StephaneLenclud@210
     8
namespace SharpLib.Ear
StephaneLenclud@210
     9
{
StephaneLenclud@210
    10
    
StephaneLenclud@210
    11
StephaneLenclud@210
    12
    [DataContract]
StephaneLenclud@231
    13
    [AttributeObject(Id = "Thread.Sleep", Name = "Sleep", Description = "Have the current thread sleep for the specified amount of milliseconds.")]
StephaneLenclud@210
    14
    public class ActionSleep : Action
StephaneLenclud@210
    15
    {
Stephane@212
    16
        [DataMember]
StephaneLenclud@231
    17
        [AttributeObjectProperty
StephaneLenclud@220
    18
            (
StephaneLenclud@220
    19
                Id = "Thread.Sleep.Timeout",
StephaneLenclud@220
    20
                Name = "Timeout (ms)",
StephaneLenclud@220
    21
                Description = "Specifies the number of milliseconds this action will sleep for.",
StephaneLenclud@220
    22
                Minimum = "0",
StephaneLenclud@220
    23
                Maximum = "10000",
StephaneLenclud@220
    24
                Increment =  "1"
StephaneLenclud@220
    25
            )
StephaneLenclud@220
    26
        ]
StephaneLenclud@219
    27
        public int TimeoutInMilliseconds { get; set; }
StephaneLenclud@210
    28
StephaneLenclud@210
    29
        public ActionSleep()
StephaneLenclud@210
    30
        {
StephaneLenclud@219
    31
            TimeoutInMilliseconds = 1000;
StephaneLenclud@210
    32
        }
StephaneLenclud@210
    33
StephaneLenclud@210
    34
StephaneLenclud@210
    35
        public ActionSleep(int aMillisecondsTimeout)
StephaneLenclud@210
    36
        {
StephaneLenclud@219
    37
            TimeoutInMilliseconds = aMillisecondsTimeout;
StephaneLenclud@210
    38
        }
StephaneLenclud@210
    39
StephaneLenclud@220
    40
        public override string Brief()
StephaneLenclud@220
    41
        {
StephaneLenclud@220
    42
            return Name + " for " + TimeoutInMilliseconds + " ms";
StephaneLenclud@220
    43
        }
StephaneLenclud@220
    44
StephaneLenclud@220
    45
StephaneLenclud@228
    46
        protected override void DoExecute()
StephaneLenclud@210
    47
        {
StephaneLenclud@219
    48
            Thread.Sleep(TimeoutInMilliseconds);
StephaneLenclud@210
    49
        }
StephaneLenclud@210
    50
StephaneLenclud@210
    51
    }
StephaneLenclud@210
    52
StephaneLenclud@210
    53
StephaneLenclud@210
    54
StephaneLenclud@210
    55
}