locked
'Executing' event (workflow activity) question RRS feed

  • Question

  • I posted this right as the forum was moving and wanted to make sure it made it to the new forum since I haven't received a reponse yet.

     

    We have a subclass of QuestionAnswerActivity that we need to do some initialization on before it runs, so in the constructor, we register a handler for the ‘executing’ event. When we use this QA in an application, when the call flow hits the QA, the event handler is not being called, Further, when the QA subclass is run, the turnStarting method is called, and then I get an exception: ‘Cannot find the activity with Name…’.

    If I remove the call that sets the handler in the constructor of the QA subclass, it all runs fine again (except of course my handler is still not being called).

    I guess the first question is when exactly does the ‘executing’ event occur?

    Can you think of any reasons why the event handler is not getting called? Why am I seeing this exception in turnStarting

    Thank you.

     

    Public class SubQa:QuestionAnswerActivity

    {

    ….

     

    public SubQa() : base()

            {

                Executing += new EventHandler<System.Workflow.ComponentModel.ActivityExecutionStatusChangedEventArgs>(Sub_Executing);

               

            }

     

    void Sub_Executing(object sender, System.Workflow.ComponentModel.ActivityExecutionStatusChangedEventArgs e)

            {

                // set some params on the recognizer

            }

    Wednesday, May 9, 2007 12:34 AM

Answers

  • Yes, you should be able to set things like InitialSilenceTimeout in ExecuteCore(), since the speech operation itself hasn't started yet.  Those sorts of settings, though, actually are good things to do in the c'tor (despite the multiple-calls thing); just make sure that none of them affect anything outside the activity being constructed.

    The few properties that you can't set while the activity is running at all (SaltActivityInterpreter.StartPage, for instance) you'll have to set in the c'tor or elsewhere, but not in ExecuteCore().

    Thursday, May 10, 2007 7:36 PM

All replies

  • I posted this to the old mailing list, too, but to make sure it makes it over here...

     

    Mike,

     

    This is an oddity of Windows Workflow.  When an event handler is registered to an Activity’s event, it “remembers” the name of the target activity.  The problem is that the name changes between construction (when a dummy name is used) and execution.  Hence the ‘Cannot find the activity with Name…” exception, if you registered the handler in a constructor.

     

    In general, a way to work around this is to attach event handlers in a code activity at the beginning of the WF instead of in c’tors.  In your case, of course, that wouldn’t work very well.  I’d recommend overriding ExecuteCore(), to make the property changes you need and then call the base QA’s ExecuteCore().  Attaching any other event handlers you need from within ExecuteCore() should work.

     

    Wednesday, May 9, 2007 11:06 PM
  • That should work.

    Can I make changes to 'speech settings' at this point in the activities execution (such as setting the initialSilenceTimeout property)?

    I know there are some properties that can't be set once an activity is running and I have only been able to set these in the constructor, even though I hate to call things in the constructor because they get called a few times as the workflow gets started up.

    Thanks for the helpful information,

    Mike

    Thursday, May 10, 2007 5:45 AM
  • Yes, you should be able to set things like InitialSilenceTimeout in ExecuteCore(), since the speech operation itself hasn't started yet.  Those sorts of settings, though, actually are good things to do in the c'tor (despite the multiple-calls thing); just make sure that none of them affect anything outside the activity being constructed.

    The few properties that you can't set while the activity is running at all (SaltActivityInterpreter.StartPage, for instance) you'll have to set in the c'tor or elsewhere, but not in ExecuteCore().

    Thursday, May 10, 2007 7:36 PM
  • Do something with it, MS. It's two years now :/
    Wednesday, May 13, 2009 9:21 AM
  • I've encounter this problem also & overided the Initialize method...problem solved..

     

    protected override void Initialize(IServiceProvider provider)

    {

     

    base.Initialize(provider);

     

    this.Executing += new EventHandler<ActivityExecutionStatusChangedEventArgs>(ServiceCallerActivity_Executing);

     

    this.Closed += new EventHandler<ActivityExecutionStatusChangedEventArgs>(ServiceCallerActivity_Closed);

     

    this.Faulting += new EventHandler<ActivityExecutionStatusChangedEventArgs>(ServiceCallerActivity_Faulting);

    }

    Good luck

    Diego


    Dieg
    Thursday, September 16, 2010 7:51 AM