Learn WF notes 9-attributes of event types in custom activities (3)

Source: Internet
Author: User

There are two types of properties in the activity Property Window. One is the common property mentioned in section 2nd, and the other is the property of the event type. You can use this property to create an event. For example, you can use the "executecode" property of the Code activity to create an event. developers can perform corresponding business operations in the event. The method for creating an event type attribute in a custom activity is basically the same as that for creating a common attribute. The "dependencyproperty" attribute is also used to manage the attribute of the event type, the corresponding property type is not "string" or "int", but an attribute of the "event" type. The Code is as follows.

Public static dependencyproperty printevent = dependencyproperty. Register ("print", typeof (eventhandler), typeof (activity1 ));

[Description ("print a string")]

[Browsable (true)]

Public event eventhandler print

{

Add {

Base. addhandler (activity1.printevent, value );

}

Remove

{

Base. removehandler (activity1.printevent, value );

}

}

The preceding procedure defines an event type attribute, but this attribute cannot be executed. You must reload the "execute" method of the parent class and use "raiseevent" to load the corresponding "dependencyproperty" attribute. The Code is as follows.

Protected override activityexecutionstatus execute (activityexecutioncontext context)

{

Base. raiseevent (activity1.printevent, this, eventargs. Empty );

Return activityexecutionstatus. closed;

}

 

Create custom Activity

You can use the preceding code to create a custom activity. After compilation, add the activity to the workflow design interface, as shown in figure 1, in the Properties window, use the "print" attribute to create an event "exeprint" for execution. The Code is as follows.

Private void exeprint (Object sender, eventargs E)

{

Console. Write ("the method printevent defined in the Custom activity is executed! \ R \ n ");
}


Figure 1

Run the workflow project. As shown in figure 2, the event "exeprint" created by the user through the attribute "print" is executed.

Figure 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.