Passing arguments to activities scheduled by NativeActivity (WF)

Passing arguments to activities scheduled by NativeActivity (WF)

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:

http://blogs.msdn.com/b/tilovell/archive/2010/02/26/misadventures-in-cachemetadata-wrapping-an-inner-activity-in-code.aspx

Leave a Comment
  • Please add 4 and 7 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Page 1 of 1 (1 items)