Lock the entire WriteFileHeader method