none
DelayActivity在使用ManualWorkflowSchedulerService调用服务时的问题 RRS feed

  • 问题

  • 在顺序工作流中如果存在DelayActivity,如果使用ManualWorkflowSchedulerService调用服务时工作流将无法正常运行。

     

    WorkflowRuntime runtime1 = new WorkflowRuntime();

    ManualWorkflowSchedulerService scheduler;
    scheduler = 
    new ManualWorkflowSchedulerService();
    runtime1.AddService(scheduler);

    WorkflowInstance instance;
    instance = runtime1.CreateWorkflow(
    typeof(Workflow1));
    Console.WriteLine(
    "Setting up workflow from thread {0}",
        Thread.CurrentThread.ManagedThreadId);
    instance.Start();
    scheduler.RunWorkflow(instance.InstanceId);

     

    • 已移动 小鱼儿 2009年5月19日 10:30 ([Loc]From:.NET Framework 相关)
    2008年8月28日 8:53

全部回复

  • 你好,你这样运行的效果是什么样的?
    是运行当中抛出异常了么?
    2008年9月3日 1:44
  • 没有抛出异常,Delay后面的CodeActity不能正常执行,流程就结束,但是状态并不正常,退出Debug时响应特别慢。

    非常简单的例子,可惜我不知道怎么上传源码。

    2008年9月3日 2:01
  • 你好,你把代码直接贴在论坛里面好了。
    大家可以帮你看看。
    2008年9月4日 2:58
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Workflow.Runtime;
    using System.Workflow.Runtime.Hosting;

    namespace TestWorkflow
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Start Manual Service");
                WorkflowRuntime runtime1 = new WorkflowRuntime();
                ManualWorkflowSchedulerService scheduler;
                scheduler = new ManualWorkflowSchedulerService();
                runtime1.AddService(scheduler);

                WorkflowInstance instance1;
                instance1 = runtime1.CreateWorkflow(typeof(Workflow1));
                Console.WriteLine("Setting up workflow from thread {0}",
                    Thread.CurrentThread.ManagedThreadId);
                instance1.Start();
                scheduler.RunWorkflow(instance1.InstanceId);
                Console.WriteLine("Manual Service");

                Console.WriteLine("Start Default Service");

                using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    AutoResetEvent waitHandle = new AutoResetEvent(false);
                    workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
                    workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(TestWorkflow.Workflow1));
                    instance.Start();
                    Console.WriteLine("Default Service");

                    waitHandle.WaitOne();
                }

                Console.ReadLine();
            }
        }
    }

    ======================================================================================

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Reflection;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;

    namespace TestWorkflow
    {
     partial class Workflow1
     {
      #region Designer generated code
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要
      /// 使用代码编辑器修改此方法的内容。
      /// </summary>
            [System.Diagnostics.DebuggerNonUserCode]
      private void InitializeComponent()
      {
                this.CanModifyActivities = true;
                this.codeActivity1 = new System.Workflow.Activities.CodeActivity();
                this.delayActivity1 = new System.Workflow.Activities.DelayActivity();
                //
                // codeActivity1
                //
                this.codeActivity1.Name = "codeActivity1";
                this.codeActivity1.ExecuteCode += new System.EventHandler(this.codeActivity1_ExecuteCode);
                //
                // delayActivity1
                //
                this.delayActivity1.Name = "delayActivity1";
                this.delayActivity1.TimeoutDuration = System.TimeSpan.Parse("00:01:00");
                //
                // Workflow1
                //
                this.Activities.Add(this.delayActivity1);
                this.Activities.Add(this.codeActivity1);
                this.Name = "Workflow1";
                this.CanModifyActivities = false;

      }

      #endregion

            private DelayActivity delayActivity1;
            private CodeActivity codeActivity1;

     

     


        }
    }

     

    ========================================================================================

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Linq;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;
    using System.Threading;

    namespace TestWorkflow
    {
     public sealed partial class Workflow1: SequentialWorkflowActivity
     {
      public Workflow1()
      {
       InitializeComponent();
      }

            private void codeActivity1_ExecuteCode(object sender, EventArgs e)
            {
                Console.WriteLine("Hello from {0}", this.QualifiedName);
                Console.WriteLine(" I am running on thread {0}",
                    Thread.CurrentThread.ManagedThreadId);
            }
     }

    }

    2008年9月5日 6:41
  • 你好,你试一试在web.config当中添加如下代码呢?

    <add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral,UseActiveTimers=true
    2008年9月8日 3:22