Using session.dispose method – Pitney Bowes MapXtreme User Manual

Page 198

Advertising
background image

Chapter 9: Working with Core MapXtreme Classes

Session Interface

MapXtreme v7.1

205

Developer Guide

Using Session.Dispose Method

The MapInfo.Engine.Session class has two overloaded Dispose methods. Your choice will depend
on the type of application you are building.

Session.Dispose()

Session.Dispose() disposes the ISession instance that is accessible through the Session.Current
property. This method is used only for multi-threaded desktop applications.

Do not use this for web applications or single-threaded desktop applications. For web applications,
ISession is managed by WebSessionActivator.

For single-threaded desktop application, Dispose is called automatically when the application is
shutdown or when the AppDomain using MapXtreme is unloaded.

Session.Dispose(HttpSessionState)

Use Session.Dispose(HttpSessionState) for web applications that use the default session state
settings in which the ISession is stored in memory. Do not call this method for any other
configuration since the ISession instance is not stored in memory in any other configuration.

The state settings are represented in the Web.config file of your application project by the following
keys:

<add key="MapInfo.Engine.Session.State" value="HttpSessionState" />
<sessionState mode="InProc" />

The first setting is an application-specific setting that controls the mechanism for saving and
restoring the state of the MapInfo.Engine.ISession instance. This instance is accessible through the
MapInfo.Engine.Session.Current property. The HttpSessionState setting indicates that the session is
saved and restored through the ASP.NET session state. This state is exposed through the current
HttpContext and is of type HttpSessionState.

The second setting is an ASP.NET setting that controls how the HttpSessionState is saved and
restored. InProc indicates that the state of the ASP.NET session is to be placed in memory and is
unique to each ASP.NET ISession instance. This is the default setting.

When you use these settings, there is an ISession instance for each ASP.NET session and it is
stored in the HttpSessionState throughout the lifetime of the ASP.NET session. In order for the
ISession instance to be properly disposed of when the session times-out or ends, you must add the
following statement to the Session_End method in your Global.asax source code file.

VB example:

MapInfo.Engine.Session.Dispose(Me.Session)

Protected Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
MapInfo.Engine.Session.Dispose(Me.Session)
End Sub

Making this call will ensure that the ISession instance is properly disposed of and that memory is
reclaimed.

Advertising