Cleaning up a session

If your application uses the using keyword, which implements the IDisposable interface, the Session object is automatically cleaned up at the end of the using block. If your application does not implement using, then you need to release the session when you've completed the transaction.

The Session class contains a Dispose method, which cleans up the 1010data Insights Platform session when it is invoked. Depending on the login type that was used to create the Insights Platform session, there are a few different ways they might be cleaned up. If you are a single user logged in with LoginType.POSSESS, the session continues to run. If you're a single user logged in with LoginType.KILL or LoginType.NOKILL, the platform session is terminated. A SAM pool user's session is released back into the pool; it is never terminated before being released.

Cleaning up a platform session when it is no longer needed is particularly important if you have multiple users sharing a pool of IDs (SAM pool). Waiting for the garbage collector to clean up Session objects may result in a pool that appears fully utilized, but is waiting for Session objects to be destroyed. For more information about SAM pools, see SAM pools and multi-threading.

The most efficient and effective way to release user IDs back to the pool is to invoke the Dispose method, either by explicitly calling it or employing using, which invokes it at the end of the block.

Via the using statement:

using System;
using TenTenSDK;

public class DocumentationExample {
    public static void PrintTable(Session testSession, String path) {
        Query exampleQuery = new Query(path,
                                       "<sel value=""(between(i_;1;10))""/>");
        using(Table resultTable = testSession.RunQuery(exampleQuery)) {
            Console.WriteLine(String.Join("\t", 
                              resultTable.Columns.Select(c => c.Info.Title)));
            foreach(Row r in resultTable.Rows) {
                Console.WriteLine(String.Join("\t", 
                                              r.Select(d => d.ToString())));
            }
        }
    }

    public static void Main() {
        Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k");
        String user = "[USER_NAME]";
        String pwd = "[USER_PASSWORD]";
        String path = "[TABLE_PATH]";
        using(Session testSession = new Session(gateway, user, pwd,
                                                LoginType.POSSESS)) {
            PrintTable(testSession, path);
        }
    }
}
Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid Insights Platform user name, password, and table path.

Explicitly calling the Dispose method:

using System;
using TenTenSDK;

public class DocumentationExample {
    public static void PrintTable(Session testSession, String path) {
        Query exampleQuery = new Query(path,
                                       "<sel value=""(between(i_;1;10))""/>");
        Table resultTable = testSession.RunQuery(exampleQuery);
        Console.WriteLine(String.Join("\t", 
                          resultTable.Columns.Select(c => c.Info.Title)));
        foreach(Row r in resultTable.Rows) {
            Console.WriteLine(String.Join("\t", 
                                          r.Select(d => d.ToString())));
        }
    }

    public static void Main() {
        Uri gateway = new Uri("https://www2.1010data.com/cgi-bin/gw.k");
        String user = "[USER_NAME]";
        String pwd = "[USER_PASSWORD]";
        String path = "[TABLE_PATH]";
        Session testSession = new Session(gateway, user, pwd,
                                          LoginType.POSSESS);
        PrintTable(testSession, path);
        testSession.Dispose();
    }
}
Note: [USER_NAME], [USER_PASSWORD], and [TABLE_PATH] are placeholders for valid Insights Platform user name, password, and table path.