Issue 50646 - Improve task handling during shutdowns
Bug Description: There is a race condition when stopping the server and
a running import task that can cause a heap-use-after-free.
Fix Description: For an import task, encapsulate the import thread with
a global thread increment/decrement (just like the export
task). Also improved how tasks are notified to abort by
notifiying them before we wait for active threads to finish.
Then the tasks get destroyed after all threads are complete.
Reviewed by: lkrispen & tbordaz (Thanks!!)