为什么在workflowapplication运行调用后使用Thread.Sleep [英] Why to use Thread.Sleep after workflowapplication run call
问题描述
嗨
我正在使用WorkflowApplication在WF.Invoking工作流程中使用statemachine。
after通过instance.Run()方法创建实例并调用工作流。
然后我调用instance.unload()。当运行方法调用相应的codeActivity时,我执行的地方正在创建书签。
但工作流程意外中止并转向执行状态。
当我保持Thread.Sleep(新TimeSpan(0,0,5))然后它正在工作。
我的代码是这样的
WorkflowApplication instance = new WorkFLowApplication(); // 仅示例代码
instance.store = somestorename;
instance.complete + = event ;
instance.run();
Thread.Sleep( new TimeSpan( 0 , 0 , 5 ))
instance.unload();
只保持Thread.Sleep(新的TimeSpan(0,0,5))正常工作。即使用一些业务逻辑执行代码活动并创建书签。
但我认为使用Thread.Sleep是不正确的设计方式。
即使我尝试使用SynchroniseContext将workflowapplication设置为同步。
但没有成功...
请帮忙解决这个
我会使用AutoResetEvent
和WaitOne
等待主机应用程序,直到工作流程完成。示例代码 [ ^ ]:
< pre lang =c#> AutoResetEvent syncEvent = new AutoResetEvent( false );
活动wf = new WriteLine
{
Text = Hello World。
};
// 使用所需的
// 工作流程定义。
WorkflowApplication wfApp = new WorkflowApplication(wf);
// 处理所需的生命周期事件。
wfApp。已完成= 委托(WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
};
// 启动工作流程。
wfApp.Run( );
// 等待已完成到达并发出信号
// 工作流程已完成。
syncEvent.WaitOne();
Hi
I am working on statemachine in WF.Invoking workflow using WorkflowApplication.
after creating instance and calling workflow by instance.Run() method.
Then instance.unload() i am calling.When run method called respective codeActivity is getting executed where i am creating the bookmarks.
But workflow aborts unexpectingly and moving to executing status.
when i keep Thread.Sleep(new TimeSpan(0,0,5)) then it is working.
My code is like this
WorkflowApplication instance = new WorkFLowApplication();// sample code only
instance.store = somestorename;
instance.complete += event;
instance.run();
Thread.Sleep(new TimeSpan(0,0,5))
instance.unload();
only by keeping Thread.Sleep(new TimeSpan(0,0,5)) its working properly. i.e. executing codeactivities with some business logic and creating bookmarks.
But i think using Thread.Sleep is not correct way of design.
Even i tried with making workflowapplication as synchronous by using SynchroniseContext.
but no success...
Please help on this
I would useAutoResetEvent
andWaitOne
to wait host application until workflow complete. sample code[^]:
AutoResetEvent syncEvent = new AutoResetEvent(false); Activity wf = new WriteLine { Text = "Hello World." }; // Create the WorkflowApplication using the desired // workflow definition. WorkflowApplication wfApp = new WorkflowApplication(wf); // Handle the desired lifecycle events. wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e) { syncEvent.Set(); }; // Start the workflow. wfApp.Run(); // Wait for Completed to arrive and signal that // the workflow is complete. syncEvent.WaitOne();
这篇关于为什么在workflowapplication运行调用后使用Thread.Sleep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!