Then should we also change the event loop in FlushPendingEvents() to see if the doc is shut down, and if so, exit early?
Then should we also change the event loop in FlushPendingEve nts() to see if the doc is shut down, and if so, exit early?