locked
get out argument when flowchart is idle RRS feed

  • Question

  • hi, i have a winform application and a flowchart that get person infromation from db and return in grid view, and becuase i need to filter by some filed like name and lastname,i want my flowchart first return whole information in gridview and go idle to get parameters to filter and again return outargument and again go to idle to recieve parameter...

    how can i get my outargument when workflow is idle ?

    Tuesday, June 25, 2013 4:57 AM

Answers

  • my problem is access to value of variable or outargument each time my work flow is idel,

    Like I said above, you can't do that directly.

    workflowapplication have a complete event that permit access to outargument, 

    That's the only place you can access the OutArgument and only if the workflow ran to completion successfully (the completion state is Closed).

    is it possible to change idle state to  "canceld" and access to outargument?

    It is possible to cancel the workflow from the idle event handler, but that still doesn't give you access to the OutArgument. See above.

    if answer is true, how can i change state when workflow is idle?

    See above.

    I've whipped up a sample project, grab it here: http://sharesend.com/t5pkju4s


    Thursday, June 27, 2013 8:35 AM

All replies

  • I think you're looking for this:

    Examining the context/arguments for an idle workflow

    You might also want to check the WorkflowApplication.Extensions property, this is a cleaner solution:

    Sharing variables between WorkFlow Application / SIngelton Workflow

    Tuesday, June 25, 2013 9:39 AM
  • tnx for reply

    but i want to get back value of out argument from workflow  to my form, when workflow state is idle, 

    (i want show outargument in gridview and with one butoon and  2textbox to filter by first name and last name , that button take texts and resumebookmark)

    Tuesday, June 25, 2013 10:54 AM
  • is there way to without persisting or trachking in database, we can access to outargument when workflow is idle?


    Tuesday, June 25, 2013 10:59 AM
  • The value of an OutArgument is only accessible from outside the workflow when it completes successfully. This is a conceptual thing. Imagine this as trying to access the return value of a method that is still running.

    If you do not want to persist, you can still take the extension path. It's easier than it sounds, although you have to slightly modify your workflows. The basic idea is that you don't "pull" state out from the workflow, but the workflow pushes the state information. First you need to have a custom class. This can be anything: POCO, INotifyPropertyChanged, etc:

    public class MyCustomExtension
    {
        public object ValueFromWorkflow { get; set; }
    }

    You need to add this extension to the workflow before starting it:

    MyCustomExtension ext = new MyCustomExtension();
    ...
    WorkflowApplication app = ...;
    app.Extensions.Add(ext);
    app.Run();

    Then you need an activity in the workflow at every point you need the value that uses this custom extension:

    public class PassValueFromWorkflowToExtensionActivity : CodeActivity
    {
       public InArgument<object> Value { get; set; }
       protected override void Execute(CodeActivityContext context)
       {
          var ext = context.GetExtension<MyCustomExtension>();
          ext.ValueFromWorkflow = this.Value.Get(context);
       }
    }

    Be warned that setting the property on the extension always happens on a threadpool thread, so you need to marshal the call to the UI thread if you want to bind your extension directly to your form. (This restriction is somewhat lifted in WPF)

    Alternatively if your workflow is never persisted you can pass an object as InArgument to the workflow instead of passing as an extension. Then you can bind it to the form and directly update values on it in the workflow. You can do this without custom activities with the AssignActivity.


    Tuesday, June 25, 2013 11:59 AM
  • thanks a lot  for descriptions,

    but how can access the extensions after pass to workflow?

    i mean how get extensions?

    because my problem is getting , not passing, i can pass argument into workflow,but not can't get variables or outargument when workflow is idle, 

    let me explain my flowchart

     my flowchart has some state, 

    1- start

    2-custom activity that gets all information in person table and assign out value of custom activity to a variable

    3-assign variable to  outargument ("outArgPersonList" )

    4-apply filtering by inargument(first time they are empty and no filter apply)

    5-bookmark(waitForResponse) to get inargument as filter parameters

    and i have a transition(or connect) to state 3.

    id want to get "outArgPersonList" each time passing parameters as bookmarks.

    you see that my flowchart never complete.


    Wednesday, June 26, 2013 5:17 AM
  • It's right there in the middle:

    var ext = context.GetExtension<MyCustomExtension>();

    The ext variable above will hold the very same object instance (of type MyCustomExtension) that you've added to WorkflowApplication.Extensions.

    Wednesday, June 26, 2013 7:35 AM
  • where of my code i can use it?

    is it possible in idle event of workflowapplication instance?

    Wednesday, June 26, 2013 1:04 PM
  • No, you can only execute code within a workflow by activities. You can simply replace the Assign activity that sets the OutArgument to the variable (in your step 3) with the custom PassValueFromWorkflowToExtensionActivity above and set it's InArgument to your variable.
    Wednesday, June 26, 2013 1:12 PM
  • my problem is access to value of variable or outargument each time my work flow is idel,

    workflowapplication have a complete event that permit access to outargument, 

    and in this event can compare satate with "ActivityInstanceState",

    is it possible to change idle state to  "canceld" and access to outargument?

    becuase " ActivityInstanceState" have "canceled" method. 

    if answer is true, how can i change state when workflow is idle?

    Thursday, June 27, 2013 5:10 AM
  • my problem is access to value of variable or outargument each time my work flow is idel,

    Like I said above, you can't do that directly.

    workflowapplication have a complete event that permit access to outargument, 

    That's the only place you can access the OutArgument and only if the workflow ran to completion successfully (the completion state is Closed).

    is it possible to change idle state to  "canceld" and access to outargument?

    It is possible to cancel the workflow from the idle event handler, but that still doesn't give you access to the OutArgument. See above.

    if answer is true, how can i change state when workflow is idle?

    See above.

    I've whipped up a sample project, grab it here: http://sharesend.com/t5pkju4s


    Thursday, June 27, 2013 8:35 AM