Release GDI lock before calling DeleteDC from RestoreDC.