How to change the Delay activity's Duration in Execute function?
-
13 martie 2012 10:28
In my code, I declare a Delay activity as child activity, and I want to change the Delay activity's Duration in Execute function.But it failed when I run it.
Code:
public sealed class DelayTest : NativeActivity
{
private Delay delay = new Delay();
private WriteLine wl = new WriteLine();
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
Console.WriteLine("meatadata!");
wl.Text = "ddddddddddddddd";
delay.Duration = new TimeSpan(0, 0, 1);//default value
base.CacheMetadata(metadata);
metadata.AddImplementationChild(delay);
metadata.AddChild(wl);
}protected override void Execute(NativeActivityContext context)
{
Console.WriteLine("执行!");
delay.Duration = new TimeSpan(0, 0, 10);//to change the value;
context.ScheduleActivity(delay, OnComplete, OnFaulted);
}private void OnComplete(NativeActivityContext context, ActivityInstance ai)
{
Console.WriteLine(ai.Activity.DisplayName + " 执行成功!");
}private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
{
Console.WriteLine(propagatedFrom.Activity.DisplayName + " 执行失败!");
}
}
Error:无法使用类型为“System.TimeSpan”的参数。请确保在活动中声明了该参数。Could anybody tell me what's wrong with my code? thanks~
- Editat de kedach 13 martie 2012 10:28
Toate mesajele
-
14 martie 2012 05:31Moderator
If you generate the value at runtime inside your Execute() method. You should consider embedding Delay inside an ActivityAction, and using InvokeAction to pass a value to it.
If the value is generated by another child activity, or comes in in an InArgument, you can use an Implementation Variable to flow the data into your delay activity, or in the Argument case, just flow the Argument in directly.
Tim- Propus ca răspuns de Tim Lovell-SmithModerator 14 martie 2012 05:31
- Marcat ca răspuns de kedach 14 martie 2012 09:24
-
14 martie 2012 09:24
If you generate the value at runtime inside your Execute() method. You should consider embedding Delay inside an ActivityAction, and using InvokeAction to pass a value to it.
If the value is generated by another child activity, or comes in in an InArgument, you can use an Implementation Variable to flow the data into your delay activity, or in the Argument case, just flow the Argument in directly.
TimTim,
I forgot to use the ScheduleAction function.
it is really big help. thanks very much!