Fixed thread destruction to properly dispose of the persistent context when inside the thread isolate.