locked
Get Variable Values from running worklfow RRS feed

  • Question

  • Hi

    Is there a way the get variable values from an running  workflow?

    e.g. My workflow contains a root activity FlowChart. The FlowChart has a variable named State (string).

    <Variable x:TypeArguments="x:String" Default="init" Name="State" />

    The workflow changes the variable "state" while executing and waits for Bookmarks to resume.

    I use a WorkflowApplication for hosting the workflow.

    What im looking for is something like this:

    string currentState = application.GetVariable("FlowChart","State").Value;

    thanks

    Friday, May 21, 2010 7:12 PM

Answers

  • Hi DirkR -

    You can use Tracking to view the values of Variables in an executing workflow.

    A sample showing this is here: http://msdn.microsoft.com/en-us/library/ee662966(v=VS.100).aspx

     

    Friday, May 21, 2010 8:49 PM
  • Hi,

    You can pass in an object as a Variable holder to the workflow instance, since you have the object reference,you can detect any change happens in the workflow.  for example

    Workflow1:
          
    Host:

        string bkName = "inputBookmarkName";

        People people = new People();

        AutoResetEvent waitHandler = new AutoResetEvent(false);

        Activity wf = new Workflow1  () {

             bookmarkName=bkName,

             peopleIn=new InArgument<People>(env=>people)

        };

        WorkflowApplication wfApp = new WorkflowApplication(wf);

        wfApp.Unloaded = (arg) => { waitHandler.Set(); };

        wfApp.Run();

        wfApp.ResumeBookmark(bkName, Console.ReadLine());

        waitHandler.WaitOne();

        Console.WriteLine("name:"+people.Name);

        Console.WriteLine("age"+people.Age);

    Type People has two properties: Name and Age.

    But using object reference to detect the value updates still has many drawbacks. say, the object reference will lost its object after the workflow is persisted.

    In my view, besides using Tracking(track custom data) mentioned by Karl, we can also create a persistence participant to store some important data to the database along with the persistence action.

    and then we can query the database against Workflow instance id when we want to resume persisted workflow instance.

    Hope it helps
    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    • Marked as answer by Andrew_Zhu Friday, May 28, 2010 3:20 AM
    Monday, May 24, 2010 7:44 AM

All replies

  • Hi DirkR -

    You can use Tracking to view the values of Variables in an executing workflow.

    A sample showing this is here: http://msdn.microsoft.com/en-us/library/ee662966(v=VS.100).aspx

     

    Friday, May 21, 2010 8:49 PM
  • Hi,

    You can pass in an object as a Variable holder to the workflow instance, since you have the object reference,you can detect any change happens in the workflow.  for example

    Workflow1:
          
    Host:

        string bkName = "inputBookmarkName";

        People people = new People();

        AutoResetEvent waitHandler = new AutoResetEvent(false);

        Activity wf = new Workflow1  () {

             bookmarkName=bkName,

             peopleIn=new InArgument<People>(env=>people)

        };

        WorkflowApplication wfApp = new WorkflowApplication(wf);

        wfApp.Unloaded = (arg) => { waitHandler.Set(); };

        wfApp.Run();

        wfApp.ResumeBookmark(bkName, Console.ReadLine());

        waitHandler.WaitOne();

        Console.WriteLine("name:"+people.Name);

        Console.WriteLine("age"+people.Age);

    Type People has two properties: Name and Age.

    But using object reference to detect the value updates still has many drawbacks. say, the object reference will lost its object after the workflow is persisted.

    In my view, besides using Tracking(track custom data) mentioned by Karl, we can also create a persistence participant to store some important data to the database along with the persistence action.

    and then we can query the database against Workflow instance id when we want to resume persisted workflow instance.

    Hope it helps
    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    • Marked as answer by Andrew_Zhu Friday, May 28, 2010 3:20 AM
    Monday, May 24, 2010 7:44 AM