restructure code so that ScanDB() can hold lock for entire scan.  Solves race condition of one thread scanning while another closes the database being scanned.