Windows Workflow基础状态机编程 [英] Windows Workflow foundation state machine programming
本文介绍了Windows Workflow基础状态机编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我是Windows Workflow基础的新手,并尝试使用对象模型编写工作流(状态机)。我正在获取此错误
StateMachineActivity1必须具有初始状态。
可以任何身体请给我答案。我的代码如下......提前致谢
Hello I am new to Windows Workflow foundation and try to write workflow (State Machine ) using Object Model. I am Getting This error
StateMachine "Activity1" Must have an initial state .
Can any body please give me answer . My code is below...Thanks in advance
Activity SMwf = new StateMachine()
{
States =
{
new State(){
Entry = new Sequence()
{
Activities = {
new WriteLine(){Text="Entry Point....."},
new Delay(){ Duration = TimeSpan.FromSeconds(30)}
}
},
Exit = new Sequence(){
Activities = {
new WriteLine(){Text = "Exit Point"},
new Delay(){ Duration = TimeSpan.FromSeconds(30)}
}
},
Transitions = {
new Transition {
DisplayName ="T1",
Action ={},
Condition={
},
}
},
DisplayName ="State1",
},
new State(){
Entry = new Sequence()
{
Activities = {
new WriteLine(){Text="Entry Point....."},
new Delay(){ Duration = TimeSpan.FromSeconds(30)}
}
},
Exit = new Sequence(){
Activities = {
new WriteLine(){Text = "Exit Point"},
new Delay(){ Duration = TimeSpan.FromSeconds(30)}
}
},
DisplayName ="State1",
}
},
DisplayName = "Activity1",
};
try
{
WorkflowInvoker.Invoke(SMwf);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
推荐答案
您需要设置 InitialState [ ^ ]到应该开始的特定状态处理。您可以在调用 WorkflowInvker.Invoke(SMwf);
之前设置它:
You need to set InitialState[^] to the particular state that should start off the processing. You could set it before you call WorkflowInvker.Invoke(SMwf);
like this:
StateMachine sm = (StateMachine)SMwf;
sm.InitialState = sm.States[0];
更好的是,不要执行转换 - 创建SMwf作为 StateMachine
而不是活动
。
Better still, don't do the cast - create SMwf as a StateMachine
instead of an Activity
.
谢谢但是现在它给出了错误Activity1必须至少有一个Transition
Thanks But Now it gives error that Activity1 must have atleast one Transition
这篇关于Windows Workflow基础状态机编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文