
	cBot
=====================

************************************************************************
* Windows
************************************************************************





WORK FLOW
=========

	hivestatus: hive name, prior refcount, refcount
	hivetounload: hive name, next attempt (60 seconds)
	pendinghiveunload: hive name, next attempt (10 seconds), last attempt (60 mins)
	handletoclose: handle info

    wait until computer has been up for 1 minute

	on profile list change notify or service done or timeout (10 seconds if !pendinghiveunload.empty else 60 seconds)
		if service done -- exit

		iterate through hive status:
			prior refcount = refcount
			update refcount
			if refcount = 0 and loaded then
				if prior refcount != 0 then
					remove hive from hivetounload
					add hive to pendinghiveunload
						(next attempt = now, last attempt = now + 65 mins)
			else
				remove hive from hivetounload
				remove hive from pendinghiveunload

		iterate through pendinghiveunload
			if last attempt passed then 
				move hive to hivetounload (next attempt = now)

		if !pendinghiveunload.empty or !hivetounload.empty then
			handletoclose = null
			get handlelist
			iterate through handlelist
				if (start(handle.name) in pendinghiveunload and nextattempt <= now) or
						(start(handle.name) in hivetounload and nextattempt <= now) then
					add entry to handletoclose

		process handletoclose (all handles on list are to be closed)

		process hivetounload (hives with nextattempt <= now should be unloaded)
			no need to remove from list (will get done at next hive status update)

