Determine when all prefs have been written to disk

This is for #7683.

This does not seem to always work. Posting for initial review.