all groups > dotnet remoting > june 2007 >
You're in the

dotnet remoting

group:

Remoting and Statics


Remoting and Statics nilesh.shah.uk NO[at]SPAM gmail.com
6/18/2007 3:37:45 AM
dotnet remoting:
Have a remoted MarshallByRef singleton class hosted in windows
service:

class Foo
{
private static readonly Bar s_someStatic =
(Bar)ConfigurationSetting.GetConfig("BarSection");
}


When a client thru remoting calls a method on Foo, it gets initialised
including statics correctly.

Within the service, I also do :
Foo f = new Foo() and it tries to init. the statics AGAIN !!!!

Why is this so and additionally the static initialisation fails !!!
with invalid cast presumably cos it could not get the required config.

Weird - help appreciated.
Re: Remoting and Statics Peter Bradley
6/18/2007 11:50:02 AM
Is it genuinely singleton, or is it SingleCall? SingleCall objects are
recreated every time a method is called on them.

If it is genuinely singleton, then it will be recreated after a timeout
period (the object's "lifetime") - either the default period or one that you
have set. I never use Singleton SAOs because of the potential threading
problems that arise if two clients access the singleton object concurrently.
Singleton objects need to be thread safe. So far I've never found the need
for a shared SAO (which is effectively what a singleton object is).

You can of course set a singleton object never to time out, but you would
then need to be very sure it was thread safe.

HTH


Peter

[quoted text, click to view]

Re: Remoting and Statics José Joye
6/18/2007 9:12:01 PM
Last week, I played with AppDomain and read information about static member
problematic.
In fact, static members get executed on the AppDomain where they are really
called (not marshalled).
I believe, you are facing the exact same behavior. The static members are
initialized twice (once on each side).

- José

<nilesh.shah.uk@gmail.com> a écrit dans le message de news:
1182163065.714976.205630@k79g2000hse.googlegroups.com...
[quoted text, click to view]

AddThis Social Bookmark Button