我创建了一个包含子活动集合的自定义原生活动。如果其中一项活动失败,我正在尝试取消子活动。调用context.CancelChildren()不会在子活动中调用取消。
下面是例子:
public sealed class MyCompositeActivity : NativeActivity
{
public Collection<Activity> Activities { get; set; }
protected override void Execute(NativeActivityContext context)
{
ScheduleActivity(context);
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.SetChildrenCollection(Activities);
}
private void ScheduleActivity(NativeActivityContext context)
{
// Get next activity
....
context.ScheduleActivity(nextActivity, OnActivityCompleted, OnActivityFaulted);
}
private static void OnActivityFaulted(NativeActivityFaultContext context, Exception exception, ActivityInstance faultedInstance)
{
context.HandleFault();
context.CancelChildren();
}
}