views:

24

answers:

1

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?

+1  A: 

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

Petar Repac