Original Post
I was just working on fine tuning my Managed DirectX framework when I noticed something that I hadn't up until now. I was using this rendering function (bare-bones & straight out of Microsoft's DirectX SDK Docs): The trouble is; if I switch application focus on my desktop, say to Internet Explorer or Media Player, those applications start to stick and my computer will slowly start to grind to a halt. Visual C# spits out an error concerning a DeviceLostException. I've worked out a solution to this (The name of the rendering device changed from 'device' to 'd3dDevice'): This works but I get the feeling there is a better way of doing it. None of the examples of Managed DirectX code I can find handle this problem, or even mention what to do when you want to write a MDX application that may loose it's focus. Has anyone else had to deal with this and am I dealing with it 'correctly'?
private void RenderDirect3D()
{
if (device == null)
{
return;
}
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
device.BeginScene();
device.EndScene();
device.Present();
}
private void RenderDirect3D()
{
try
{
d3dDevice.Clear( ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0 );
d3dDevice.BeginScene();
d3dDevice.EndScene();
d3dDevice.Present();
}
catch( DeviceLostException )
{
return;
}
return;
}