Understanding SAO and CAO Activation Methods in .NET Remoting
page 4 of 9
by Abhishek Kumar Singh
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 42009/ 124

Overall Processing Steps in SAO - Singleton

Let us assume that Server S starts listening for the client's call. The very first client, CLIENT_A, creates a remote object in OnStart(). At this moment no activity happens at the server, meaning the remote object instance creation does not request any from server. CLIENT_A makes the first remote method call, then server initializes its class object (so runs default constructor New()) at the first time. Hence, the server initializes all member variables ONLY at the very first remote method call from the very first client. Remember, this happens only once unless and until the server remote application is stopped and started again. This is true even after some time if no client calls come for long (there is a default idle timeout set for the server which I will discuss later), and any new/old client starts method call again.

That is why we can do state management among several clients in SAO-Singleton activation, since member variable remains common and active in the server memory during its lifetime. All these are possible because the server has only one remote object instance in the member at any case.


SAO can support only default constructor. SAO can never be more than one instance of the server object at any point of time.

But Singleton server object would be garbage collected at the server if it remains inactive up to its default LEASE-BASE LIFETIME. Default time is 5 minutes for the first time and 2 minutes for the rest. Lease time is the duration unto which object should remain in memory, preventing it from automatic garbage collection.

Once the server object instance is created it will exist and server all clients unless and until the server application gets stopped intentionally or unintentionally.

To increase or decrease this default lifetime, add the following namespace in server class:

Imports System.Runtime.Remoting.Lifetime.

You can override the InitializeLifetimeService method as given below (this sample code is taken from msdn).

Listing 4: Overriding InitializeLifetimeService method

Public Overrides Function InitializeLifetimeService() As Object
        Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
        If lease.CurrentState = LeaseState.Initial Then
            lease.InitialLeaseTime = TimeSpan.FromMinutes(1)
            lease.SponsorshipTimeout = TimeSpan.FromMinutes(2)
            lease.RenewOnCallTime = TimeSpan.FromSeconds(2)
        End If
        Return lease
End Function

You can explore more on it if you wish. See MSDN for more information about it.

For infinite lease time set ease.InitialLeaseTime = Nothing.

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2023 ASPAlliance.com  |  Page Processed at 2023-09-29 12:24:50 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search