Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a static class which has some static data. What happens to the data if its accessed from different app domain?

  1. Will there a copy of a static class for each domain?

  2. Will the primitive types be copied?

  3. What if the data is serializable?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
844 views
Welcome To Ask or Share your Answers For Others

1 Answer

The memory between AppDomain's is not shared. By default the objects are a deep clone, if they are MarshalByRef then its similar to remoting where the calls are executed across AppDomain, so it appears that its shared state.

MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.

I don't believe you can actually invoke static members using the AppDomain methods, your best bet would be to wrap the static calls in an instance class and use DoCallback to execute that code in the other domain and collect the state in a MarshalByRef object.

See the example on MSDN


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...