开发者

InvokeMethod in Workflow 4.0

We have an application where we are creating an activity (say = CallA), this activity will be used in the worklfow project. This activity(CallA) will call a method which is present i开发者_Python百科n another class(and another namespace). I have written a sample code for the method being called below :-

    namespace WorkflowApplication1
{
    class Class1
    {
        public int Trial(int a, int b)
        {
            return 23;
        }
    }
}

We want to use InvokeMethod feature provided in the toolbox and don't want to use codeactivity.

If anybody has used this feature of WF 4.0, please help.

Thanks in advance.


In the target type you have to point to the class that implements the method.

In the method name you'll have to write the name. If the method is not static, then you'll need to create a variable of that class type, initialize it in advance and use it in the TargetObject property. You'll need a variable in your WF to store the result (using Result property on the Invoke activity)

Hope it helps


Here follows a suggestion for this question

1) Create a Windows Forms Application
2) Add a Class called Class 1 and change the namespace to WorkflowApplication1
3) Change the whole code from Class 1 to

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkflowApplication1
{
    public class Class1
    {
        public int Trial(int a, int b)
        {
            return 23;
        }
     }
}

4) Add an Activity called Activity1
5) Compile the solution
6) Open the Activity1 and add a sequence
7) Click on the sequence and create 2 variables, as shown below

InvokeMethod in Workflow 4.0

8) Insert a InvokeMethod and a Writeline activities, as shown below

InvokeMethod in Workflow 4.0


9) Edit the parameters of the Invoke Method, as shown below

InvokeMethod in Workflow 4.0

10) Add a button and click it twice to create the Click event
11) Add the following piece of code inside your Form1 class and change the button1_Click event

namespace Generic
{

public partial class Form1 : Form
{

    WorkflowApplication WFApp = null;
    AutoResetEvent WFAppEvent = null;

    public void RunWFApp()
    {
        WFAppEvent = new AutoResetEvent(false);
        WFApp = new WorkflowApplication(new Activity1());

        WFApp.Completed = delegate (WorkflowApplicationCompletedEventArgs e)
        {
            WFAppEvent.Set();
        };
        WFApp.Run();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        RunWFApp();
    }

    ...
    ...
    }
}

12) Open the Output window (Ctrl-Alt-O). Run the application, click the button and check if the number 23 is shown in the output window

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜