If the blend file is saved from a script in another thread,
like the render thread for example, Blender will crash on the call that
redraws the UI.
This patch adds a check to ensure that the UI is only redrawn if the redraw call is done in the main thread. This avoids the crash, and preserves the desired function of the redraw call to ensure that open menus are closed when a screenshot of Blender's UI is taken for use in file thumbnails.