Search code examples
c#staticbiztalkapplicationdomain

What is the scope of a Static Class?


I have an assembly that may be used by more than one process at a time. If I am using a static class, would the multiple processes all use the same "instance" of that class?

Since the processes are separate, would these be running under difference Application Domains, hence have the static "instances" separate?

The pudding in the details here is that the assembly is being used by a custom BizTalk adapter that my be set to process the messages in parallel batches. That is what I am calling "multiple processes" above.


Solution

  • Multiple threads would share an instance. For this reason a static class can be convenient for passing state between threads, but you need to be very careful not to introduce race conditions (Monitor or lock your properties).

    However, multiple processes should be in separate AppDomains and therefore each have their own instance.