Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
When scheduling activities using the NativeActivityContext.ScheduleActivity method, it isn't immediately obvious how to flow arguments into that activity. Since the scheduled activity doesn't have access to the parent activity's arguments (as a child activity would), it's necessary to use a Variable to transmit the data.
The following code snippet demonstrates how to pass an argument from a native activity into a scheduled activity.
public sealed class ChildActivity : NativeActivity
{
public WriteLine _writeLine;
public InArgument<string> Message { get; set; }
private Variable<string> MessageVariable { get; set; }
public ChildActivity()
{
MessageVariable = new Variable<string>();
_writeLine = new WriteLine
{
Text = new InArgument<string>(MessageVariable),
};
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.AddImplementationVariable(this.MessageVariable);
metadata.AddImplementationChild(this._writeLine);
}
protected override void Execute(NativeActivityContext context)
{
string configuredMessage = context.GetValue(Message);
context.SetValue(MessageVariable, configuredMessage);
context.ScheduleActivity(this._writeLine);
}
}
The issue is discussed in more detail in the following blog post: