WF4.0 Combat (22): an example of a state machine in real life

Source: Internet
Author: User

This is an example of a state machine in real life: "The Door". This example is written by Mebyon Kernow, using the state machine to control the state of the door, which I think is a good example of learning the state machine in WF4.0. So, a simple translation of his article. I hope it will help you to learn WF4.0 's state machine. The following is the text. The original is: A Practical State Machine Example

Now, the state machine activity has been posted on the CodePlex (see: http://wf.codeplex.com/). I find an example that is often used. Use this example to demonstrate how to use a state machine to control the access of a building (control the building's doors) and to show the main functions in the state machine activity package.

The model of this example is the control of the portal. The host is a WPF application (WPF can implement some of the better styles!) )。 Imagine if you were to ' open ' a building. At this point, each door is closed or locked, which forms the state of the state machine initialization in this example. Therefore, in the state machine we need to wait for an event trigger to unlock the door, the reality may be to use the password keyboard or smart card to unlock. The state and transition of this example are shown in the following illustration:

When the user provides his or her credentials to trigger the transition-in the image above, you may need to pass the PIN number (or the number on the card) to transition, and then query the database for verification. \ unlocked For the sake of simplicity, there is no validation in this example.

From the closedlocked state, there are three possibilities. One is for the user to open the door; one is to lock the door for some reason; one possibility is that he did not open the door, after a period of time automatically lock the door, back to the closedlocked state. In this state, three transition are executed, of which two are waiting for the event to occur, and the third is to use a delay activity, with a time set to 5 seconds. Next, I'll explain state and transition, which are critical to understanding how the machine works.

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.