taken from quartz with only minor adaptions.
and server locking based on how it is done with DirectX samples.