What is the scope of a Static Class?

后端 未结 5 662
小蘑菇
小蘑菇 2020-12-14 18:56

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 cla

5条回答
  •  隐瞒了意图╮
    2020-12-14 19:36

    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.

提交回复
热议问题