locked
Workflow 4 , in Custom activity call another activity RRS feed

  • Question

  • Hi,

    I want to call a Delay activity in my custom code execute activity, please suggest correct way.

     protected override void Execute(CodeActivityContext context)
            {
    
    // Based on some business condition
     Delay d = new Delay();
             d.Duration = new TimeSpan(0, 0, 30);
            WorkflowInvoker.Invoke(d);
    
    }
    Can any one suggest a way to achieve the same, to have the delay in execute method.


    regards Vimal


    • Edited by singhal Monday, June 24, 2013 8:16 AM more info
    Saturday, June 22, 2013 3:09 PM

Answers

  • I think you are supposed to use the NativeActivityContext.ScheduleActivity overloads. That means you have to derive from NativeActivity instead of CodeActivity. The execution of the child activity will only start once the Execute method returns, so pass in a completion callback if you need to do additional stuff in the parent activity.

    You might want to consider creating a composite activity from primitives, e.g.

    public class MyCustomActivity : Activity
    {
       public MyCustomActivity()
       {
          this.Implementation = delegate
          {
             return new Sequence()
             {
                Activities =
                {
                   new Delay() { Duration = new TimeSpan(0, 0, 30) },
                   new MyOtherActivity(),
                }
             };
          }
       }
    }
    
    This is more or less the same that you can achieve using the designer (xaml)

    • Marked as answer by Molly Chen_ Friday, June 28, 2013 9:59 AM
    Monday, June 24, 2013 8:25 AM

All replies

  • I think you are supposed to use the NativeActivityContext.ScheduleActivity overloads. That means you have to derive from NativeActivity instead of CodeActivity. The execution of the child activity will only start once the Execute method returns, so pass in a completion callback if you need to do additional stuff in the parent activity.

    You might want to consider creating a composite activity from primitives, e.g.

    public class MyCustomActivity : Activity
    {
       public MyCustomActivity()
       {
          this.Implementation = delegate
          {
             return new Sequence()
             {
                Activities =
                {
                   new Delay() { Duration = new TimeSpan(0, 0, 30) },
                   new MyOtherActivity(),
                }
             };
          }
       }
    }
    
    This is more or less the same that you can achieve using the designer (xaml)

    • Marked as answer by Molly Chen_ Friday, June 28, 2013 9:59 AM
    Monday, June 24, 2013 8:25 AM
  • hi,

    The activity which i am trying to build to but the delay based on some condition and after some delay i have to again query and find if condition satisfied if not then i have to again put in delay, this i want to do with codeactivity or by native activity.

    any suggestion


    regards Vimal

    Friday, June 28, 2013 12:31 PM
  • It's much easier to do this with a composite activity, like a FlowChart. You start at your query activity, then a Decision node which loops back through a Delay activity to the query activity. It's very easy to create this in the designer. Creating it in code is not impossible but much harder to do.

    Whether you write a CodeActivity, a NativeActivity or a composite activity is an implementation detail, it doesn't really matter. The simplest non-blocking code is best implemented as a CodeActivity. Somewhat more complex or simple bookmarking code is easier as a NativeActivity. When you have branches or loops intermingled with various async continuations (including bookmarks) that's much much easier to implement and maintain (!) as a composite activity. Otherwise you get the same class that you can new up and pass around, no difference there.

    Friday, June 28, 2013 4:08 PM