Adding Delay action to replace our Sleep action.
authorStephaneLenclud
Wed, 31 Aug 2016 16:24:33 +0200
changeset 2633ab73a2a72d8
parent 262 c4749a27966d
child 264 4a08e1b7ba64
Adding Delay action to replace our Sleep action.
SharpLibEar/ActionDelay.cs
SharpLibEar/ActionSleep.cs
SharpLibEar/SharpLibEar.csproj
     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
     2.1 --- a/SharpLibEar/ActionSleep.cs	Wed Aug 31 16:06:47 2016 +0200
     2.2 +++ b/SharpLibEar/ActionSleep.cs	Wed Aug 31 16:24:33 2016 +0200
     2.3 @@ -20,8 +20,8 @@
     2.4                  Name = "Timeout (ms)",
     2.5                  Description = "Specifies the number of milliseconds this action will sleep for.",
     2.6                  Minimum = "0",
     2.7 -                Maximum = "10000",
     2.8 -                Increment =  "1"
     2.9 +                Maximum = "60000",
    2.10 +                Increment =  "1000"
    2.11              )
    2.12          ]
    2.13          public int TimeoutInMilliseconds { get; set; }
     3.1 --- a/SharpLibEar/SharpLibEar.csproj	Wed Aug 31 16:06:47 2016 +0200
     3.2 +++ b/SharpLibEar/SharpLibEar.csproj	Wed Aug 31 16:24:33 2016 +0200
     3.3 @@ -65,6 +65,7 @@
     3.4    <ItemGroup>
     3.5      <Compile Include="Action.cs" />
     3.6      <Compile Include="ActionCallback.cs" />
     3.7 +    <Compile Include="ActionDelay.cs" />
     3.8      <Compile Include="ActionLaunchApp.cs" />
     3.9      <Compile Include="ActionOpticalDriveEject.cs" />
    3.10      <Compile Include="ActionSleep.cs" />