locked
Activity Execution Status RRS feed

  • Question

  • Hi All,

    I have developed a custom activity Sent Mail. I want to check the status of Sent Mail Activity .. 

    During Execution it is entering the status of activity .i.e Executing and Completed only when the activity go completed not during start and end separately.

    Is it possible to have status on different execution point if yes then how we can do it..

    Friday, May 11, 2012 10:08 AM

Answers

  • When the Execute method of an activity is executing, any future work items that may result as of code in that execute method are scheduled, and then occur after the execute method returns. Nothing can interrupt an activity's execute method; not termination or cancellation or anything (anything that I can think of, I don't want to say *nothing* because there probably is something). If you want something to happen right away you can do it from the workflow thread (lines of code inside the execute method, for example you could call a workflow extension and send status information that way), or you can break the execution into multiple pulses of workflow scheduling (BeginExecute, EndExecute, and o the work on another thread)

    I was about to send a link to how to create a custom extension when I found this other thread that discusses a similar situation.

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/8ce5dee9-9a19-4445-ad7f-33e181ec228b

    Here is a thread that discusses how to create a workflow extension:

    http://social.msdn.microsoft.com/Forums/sv-FI/wfprerelease/thread/59855d58-84df-41a0-8fd5-13fecea968b2

    If you need immediate communication from the workflow to the host to report status during the execution of an Activity's Execute override, one of these approaches is probably the best way to go.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    • Marked as answer by LeoTang Sunday, May 20, 2012 12:12 AM
    Thursday, May 17, 2012 2:52 PM
  • What you are doing there is just moving the emitting of the tracking records to a new spot but it is still executing on the workflow thread and all it does is schedule the tracking records with the runtime (which will get to them when it finishes its current burst of work of executing the execute override). As you have observed, those records won't get written until after Execute returns. What I meant was that in your extension you could write to another database or perform some other sort of communication with your host, or writing a log file, or something that that would be immediate and controlled by you (where the writing of tracking records is controlled by the runtime)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Monday, May 21, 2012 2:14 PM

All replies

  • Which class are you using.  Are you using SMTP Client?  The SMTP Client has callback functionality where you will get different events occuring which the message is beiong sent.

    jdweng

    Friday, May 11, 2012 10:39 AM
  • >not during start and end

    What kind of Start and End are you talking about, is this something to do with BeginExecute() and EndExecute() in an AsyncCodeActivity?

    Tim

    Sunday, May 13, 2012 7:18 AM
  • Thanks everyone for spending quality time on my issue

    Scenario is i have written a custom actvity SendMail

    ========================================

    SendMail: Native Activity

    Execute(){//some piece of code to sent mail to user }

    ========================================

    Now i want to track the status of this actvity .. I have attached the tracking with my application

    But what happens it enter the the Executing and completed status in DB only when it has completed the execution

    not in seperate go means if i write Threading.Sleep(2000) inside the Execute method and try to see the respective DB tables i am not able to see any related status record for that activity but as sson as that activity execution is over i am able to view the status in the respective DB table....

    Please let me know whether this is happening correctly or in order to have seperate executino i need to modify some thing

    With Regards

    Gaurav

    Tuesday, May 15, 2012 3:27 AM
  • html,body{padding:0;margin:0;font-family:Verdana,Geneva,sans-serif;background:#fff;}html{font-size:100%}body{font-size:.75em;line-height:1.5;padding-top:1px;margin-top:-1px;}h1{font-size:2em;margin:.67em 0}h2{font-size:1.5em}h3{font-size:1.16em}h4{font-size:1em}h5{font-size:.83em}h6{font-size:.7em}p{margin:0 0 1em;padding:0 .2em}.t-marker{display:none;}.t-paste-container{position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden}ul,ol{padding-left:2.5em}a{color:#00a}code, pre{font-size:1.23em}
    Hi Gaurav,

    It should work , Please go through following link and check ActivityStateQuery


    Code should be somthing like this:-

     


    TrackingProfile sampleTrackingProfile = new TrackingProfile()
     
                    {
     
                        Name = "Sample Tracking Profile",
     
                        Queries =   
       {
         new ActivityStateQuery()
     
               {                           

                   ActivityName = "SendEmailActivity",
       
                     States = { ActivityStates.Executing }
     
               }
     
        }
     
    Another way is that you can store required data in your custom tables. insert data in tables when activity is executing or completes



    MB

    Tuesday, May 15, 2012 4:07 AM
  • The WF runtime doesn't track the beginning and end of a sleep statement simply because it doesn't do anything magical like injecting extra code inside of your Execute() method.

    You, however, are fully in control of the Execute() method implementation, and can add custom code to emit extra custom tracking records as part of your activity Execute() statement. Like this

    (example from the Custom Tracking documentation page)

    // Create the Custom Tracking Record CustomTrackingRecord customRecord = new CustomTrackingRecord("OrderIn")
    {
        Data =
        {
            {"OrderId", 200},
            {"OrderDate", "20 Aug 2001"}
        }
    };

    // Emit custom tracking record
    context.Track(customRecord);

    Hope this helps,
    Tim

    Tuesday, May 15, 2012 5:39 AM
  • Thanks Tim and everyone ...

    Tim i have tried to use Custom Tracking also in my custom code activity

    But it is entering the Custom Tracking Data only when it is finished with the activity..

    My goal is to keep track of the activity status during execution of the long running  activity .. Now whathappens it is storing the execution status(started and Completed) when the Activity gots completed .so in case long running activity is in  middle of its execution how i can track what it's status ...

    With Regards

    Gaurav

    Wednesday, May 16, 2012 6:02 AM
  • Hi,

    I notice you mention "during the execution of the long running activity", but since we are talking about email, you mean a moment or two rather than a long running activity that waits for a manager approval for example that could take days. For activities that could take a moment or two to execute, and it is actually doing some work rather than waiting for an outside event, an AsyncCode activity might be a good choice: Creating Asynchronous Activities

    You could emit your "before" custom tracking record in BeginExecute, and your "after" custom tracking record in EndExecute. Because control returns to the workflow runtime after BeginExecute, your "before" tracking record should be processed. Then after the activity completes, the "after" record will be processed.

    It may also just be a timing thing; if your SendMail executes quickly the tracking records may come in asynchronously.

    If your activity does any work that could block the thread for any aprpeciable amount of time, and especially if there are other activites in parallel that could be executing, the AsyncCodeActivity approach is a good choice to consider.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Wednesday, May 16, 2012 1:39 PM
  • Thanks Steve...

    I totally agree with you that if i use the Asynchronus Activity i can get the desired result that is saving the status of Activities Executing and Completed in different go...

    But what if the activity is a code activity or a  native activity .. is it possible to achieve the above requirement ??

    If yes then anyone can throw some lights on it...It will be really helpful..

    With Regards

    Gaurav

    Thursday, May 17, 2012 4:53 AM
  • When the Execute method of an activity is executing, any future work items that may result as of code in that execute method are scheduled, and then occur after the execute method returns. Nothing can interrupt an activity's execute method; not termination or cancellation or anything (anything that I can think of, I don't want to say *nothing* because there probably is something). If you want something to happen right away you can do it from the workflow thread (lines of code inside the execute method, for example you could call a workflow extension and send status information that way), or you can break the execution into multiple pulses of workflow scheduling (BeginExecute, EndExecute, and o the work on another thread)

    I was about to send a link to how to create a custom extension when I found this other thread that discusses a similar situation.

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/8ce5dee9-9a19-4445-ad7f-33e181ec228b

    Here is a thread that discusses how to create a workflow extension:

    http://social.msdn.microsoft.com/Forums/sv-FI/wfprerelease/thread/59855d58-84df-41a0-8fd5-13fecea968b2

    If you need immediate communication from the workflow to the host to report status during the execution of an Activity's Execute override, one of these approaches is probably the best way to go.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    • Marked as answer by LeoTang Sunday, May 20, 2012 12:12 AM
    Thursday, May 17, 2012 2:52 PM
  • Thakns Steve for the links and info..

    I am still facing same issue ..

    I have written an extension

    ==================================

    public class TestExtesion : IWorkflowInstanceExtension
        {
            private WorkflowInstanceProxy instance;

           public void DoSomething(NativeActivityContext context,bool isStarted)
           {
               CustomTrackingRecord record =new CustomTrackingRecord("Testing");
               if (isStarted)
               {
                   record.Data.Add(new KeyValuePair<string, object>("STARTED", DateTime.Now));
               }
               else
               {
                   record.Data.Add(new KeyValuePair<string, object>("FINISHED", DateTime.Now));
               }
               context.Track(record);

           }

           #region IWorkflowInstanceExtension Members

           public IEnumerable<object> GetAdditionalExtensions()
           {
               return null;

           }

           public void SetInstance(WorkflowInstanceProxy instance)
           {
               this.instance = instance;
           }

           #endregion
        }

    ===========================================================

    Calling this in the Native Activity

    public sealed class SendMailActivity : NativeActivity
        {
          
    protected override void Execute(NativeActivityContext context)
            {
                TestExtesion extension = context.GetExtension<TestExtesion>();
                extension.DoSomething(context,true);
    }}

    ========================================================

    Still it is inserting the values in DB only when the activity got completed ... not inserting thevalues in DB in Different go....

    Please let me know if anything i am doing wrong ...

    With Regards

    Gaurav


    Monday, May 21, 2012 7:11 AM
  • What you are doing there is just moving the emitting of the tracking records to a new spot but it is still executing on the workflow thread and all it does is schedule the tracking records with the runtime (which will get to them when it finishes its current burst of work of executing the execute override). As you have observed, those records won't get written until after Execute returns. What I meant was that in your extension you could write to another database or perform some other sort of communication with your host, or writing a log file, or something that that would be immediate and controlled by you (where the writing of tracking records is controlled by the runtime)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Monday, May 21, 2012 2:14 PM