WF4:当前应用程序域中有许多动态程序集?

发布于 2024-09-16 15:08:53 字数 1330 浏览 1 评论 0原文

完整代码:

using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;

namespace ManyAssemblies {

  class Program {

    public sealed class SayHelloActivity : Activity {
      readonly WriteLine writeLine = new WriteLine() { Text = "Hello Workflow 4" };
      public SayHelloActivity() {
        Implementation = () => { return writeLine; };
      }
    }


    static void Main(string[] args) {
      var wfDefinition = new SayHelloActivity();

      for (int i = 0; i < 100; i++) {
        WorkflowInvoker.Invoke(wfDefinition);
      }

      var allLoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
      int wfAssemblesCount = allLoadedAssemblies
        .Where(a => a.FullName == 
"Workflow, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").Count();
      Console.WriteLine(string.Format("There are {0} workflow assemblies in app domain.", wfAssemblesCount));
      Console.ReadLine();
    }
  }
}

此代码的输出:

...
Hello Workflow 4
Hello Workflow 4
Hello Workflow 4
There are 100 workflow assemblies in app domain.

wf 定义的每次执行都会创建在当前应用程序域中加载的新动态程序集。 为什么?定义总是相同的,所以这没有必要,IMO。这是WF4的设计缺陷吗?这种行为可以控制吗?

我正在为工作流实例构建主机。而且该主机必须启动并运行很长时间,例如几个月。即使只有很少的工作流定义,我最终会得到包含数千个动态程序集的应用程序域吗?这会影响我的表现并耗尽我的内存吗?

Full code:

using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;

namespace ManyAssemblies {

  class Program {

    public sealed class SayHelloActivity : Activity {
      readonly WriteLine writeLine = new WriteLine() { Text = "Hello Workflow 4" };
      public SayHelloActivity() {
        Implementation = () => { return writeLine; };
      }
    }


    static void Main(string[] args) {
      var wfDefinition = new SayHelloActivity();

      for (int i = 0; i < 100; i++) {
        WorkflowInvoker.Invoke(wfDefinition);
      }

      var allLoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
      int wfAssemblesCount = allLoadedAssemblies
        .Where(a => a.FullName == 
"Workflow, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").Count();
      Console.WriteLine(string.Format("There are {0} workflow assemblies in app domain.", wfAssemblesCount));
      Console.ReadLine();
    }
  }
}

The output from this code:

...
Hello Workflow 4
Hello Workflow 4
Hello Workflow 4
There are 100 workflow assemblies in app domain.

Every execution of wf definition creates new dynamic assembly that is loaded in current app domain.
Why? Definition is always the same so this is not necessary, IMO. Is this a design flaw in WF4? Can this behavior be controlled?

I'm building a host for workflow instances. And this host must be up and running for long time, like months. Will I end up with app domain with many thousands of dynamic assemblies, even if there are only just few workflow definitions? Will this kill my performance and use up my memory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女中豪杰 2024-09-23 15:08:53

事实证明这是因为附加的调试器。

如果我直接在命令提示符中运行代码,在这种情况下,应用程序域中没有“Workflow,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null”程序集。

有趣的是没有。

这是否意味着在每个 WorkflowInvoker.Invoke(wfDefinition); 上是否存在在实例竞争时卸载的动态组件的构建?

但这是一个实现细节,可能不会影响 wf 应用程序的性能。

感谢您的帮助

It turns out that this is because of attached debugger.

If I run the code directly in command prompt, in that case there were no "Workflow, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" assemblies in app domain.

Interesting that there is none.

Does this mean that on every WorkflowInvoker.Invoke(wfDefinition); there is building of dynamic assembly that is unloaded upon instance competition ?

But this is an implementation detail that probably doesn't influence performance of an wf app.

Thanks for help tilovell

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文