18.5 Creating Server-Activated Singleton Objects

 <  Day Day Up  >  

You want to share state between multiple clients by using a single object on the server.


Technique

To configure a remoting object as a singleton object, all you have to do is call the method RegisterWellKnownServiceType with the option WellKnownObjectMode.Singleton :

 
 RemotingConfiguration.RegisterWellKnownServiceType(         typeof(_1_RemoteObject.RemoteObject), "Demo",         WellKnownObjectMode.Singleton); 

Comments

Configuring the object as a singleton object has the effect that only one object is created, and every client gets a reference to the same object. With such a behavior, you have to pay attention to threading issues. With multiple clients, the same object might be accessed from multiple threads simultaneously , and you have to pay attention to locking issues.

Singleton objects do have a timeout with the leasing mechanism similar to client-activated objects. Recipe 18.9 discusses how you configure the timeout values.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net