使用 C# 在 Direct3D 中执行 CTRL ALT DEL 期间出现 DeviceLostException
我正在使用 Microsoft.DirectX 和 Microsoft.DirectX.Direct3D 引用在我的表单上进行一些绘图。当我运行程序并且用户在 Windows XP 中按 CTRL ALT DEL 并调出“Windows Security”表单时,当返回到表单时,会引发 DeviceLostException ,并且在尝试处理此异常时似乎没有办法把它拿回来。
我对这个问题做了一些研究,并尝试了几种编码解决方案。
try
{
_d3ddevice.Present();
}
catch
{
DeviceLost = true;
}
if (DeviceLost)
{
AttemptRecovery();
}
this.Invalidate();
ReadKeyboard();
base.OnPaint(e);
}
private void AttemptRecovery()
{
try
{
_d3ddevice.TestCooperativeLevel();
}
catch (DeviceLostException)
{
Application.Exit();
}
catch (DeviceNotResetException)
{
try
{
_d3ddevice.Reset(_params);
DeviceLost = false;
InitGraphics();
CameraPositioning();
VertexDeclaration();
IndicesDeclaration();
}
catch (DeviceLostException)
{
}
}
}
当程序调用 TestCooperativeLevel() 时,它会在线表示,如果再次捕获 DeviceLostException,则尝试重置设备是没有意义的。
我该如何重置设备并继续在表单中绘图?
I am using the Microsoft.DirectX and Microsoft.DirectX.Direct3D references to do some drawing on my form. While I am running the program and the user presses CTRL ALT DEL in Windows XP and brings up the "Windows Security" form, when returning back to the Form, a DeviceLostException is thrown and when trying to handle this exception there seems to be no way to get it back.
I have done a little research into the matter and have tried several coding solutions.
try
{
_d3ddevice.Present();
}
catch
{
DeviceLost = true;
}
if (DeviceLost)
{
AttemptRecovery();
}
this.Invalidate();
ReadKeyboard();
base.OnPaint(e);
}
private void AttemptRecovery()
{
try
{
_d3ddevice.TestCooperativeLevel();
}
catch (DeviceLostException)
{
Application.Exit();
}
catch (DeviceNotResetException)
{
try
{
_d3ddevice.Reset(_params);
DeviceLost = false;
InitGraphics();
CameraPositioning();
VertexDeclaration();
IndicesDeclaration();
}
catch (DeviceLostException)
{
}
}
}
When the program calls TestCooperativeLevel(), it said online if it catches the DeviceLostException again that there is no point in trying to reset the device.
What can I do to reset the device and continue drawing in my form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
4 点中的 2 件事:
Reset
方法。2 things in 4 points :
Reset
method.