Singleton Objects

Singleton objects resemble client-activated objects in that they retain state; but the server, not the client, creates them. Only one instance of a singleton object is ever created, and it can serve any number of concurrent clients. Because the .NET Remoting services are multithreaded, clients can call methods on this object simultaneously. However, you must ensure that the object itself is thread-safe. If you modify a member variable in a singleton method, for example, you must ensure that you obtain an exclusive lock first. Otherwise, updates might be lost or inconsistent data might be applied.

We can alter the preceding example to use a singleton object without worrying. The single GetActiveDomain method just returns a static ...

Get Microsoft® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.