ImageGear .NET v25.0 - Updated
Scanner Service and Session
User Guide > How to Work with... > Common Operations > Scanning > Web-Based Scanning > Scanner Service and Session

The ImGearIsisScannerService class can be used to create an ImGearIsisScannerSession by calling the createSession method, and only one ImGearIsisScannerSession can be used at a time. An ImGearIsisScannerSession has a read-only scanner property and can be used to create an ImGearIsisScanJob to begin scanning, and these are described in more detail in the Scanner Selection, Scanner Settings and Scan Job topics. 

When any asynchronous method is called, a callback parameter is used so the customer can be notified when the task completes. Also, an ImGearIsisStatus object is returned so the customer can check the status of the task.

The code below demonstrates creating an ImGearIsisScannerService, calling the createSession method, and accessing the session in the callback:

JavaScript Example
Copy Code
            var scannerSession;
…
            function createSessionCallback(theScannerSession, status) {
                if (status.get_status() !== ImageGear.Web.Isis.ImGearIsisStatus.Completed) {
                    alert(status.get_statusMessage());
                }
                // Store the scanner session.
                scannerSession = theScannerSession;
            }
            var scannerService = new ImageGear.Web.Isis.ImGearIsisScannerService();
            scannerService.createSession({ applicationName: ‘ImageGear ISIS Application’, destroyExistingSession: true, locale: ‘en-us’, idleTimeoutMinutes: 0, callback: createSessionCallback });

The ImGearIsisScannerSession.destroy method can be used to destroy a scanner session. To ensure that the runtime is available to other applications when your application exits, you must explicitly end the session. You can end the session automatically when the web page is closed by assigning an event handler to the onunload property of the HTML body element. This is demonstrated in the ASP.NET Isis sample and shown below:

JavaScript Example
Copy Code
<body>
…
  <script type="text/javascript">
    window.onunload = onPageUnload;
    function onPageUnload() {
      if (scannerSession) {
        scannerSession.destroy();
      }
    }
  </script>
</body>