我有一个使用 SFML.Net 的简单 C# 应用程序/游戏,目前在执行后 1 或 2 秒内停止运行/终止,没有任何警告、异常等。考虑以下代码:
public static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
--> The following two lines are run
Console.WriteLine("Hello");
Console.WriteLine("Please don't go...");
// Run the game
try
{
--> This line is reached
Game.Run();
}
catch (Exception e)
{
--> This line is never reached
Console.WriteLine(e.Message.ToString());
}
--> These lines are never reached
Console.WriteLine("Noone ever comes here, I feel so lonely... :(");
Console.ReadKey();
}
}
此时您可能认为 Game.Run() 方法有问题。奇怪的是,根据 VS 调试器,方法的第一行永远不会到达。
public static void Run()
{
try
{
--> Never reached
LoadContent();
// Do stuff here
while (window.IsOpen())
{
// The classic game loop
}
}
catch (Exception e)
{
--> Never reached
Console.WriteLine(e.Message.ToString());
Console.ReadKey();
}
}
请您参考如下方法:
我的猜测是:
- 您收到一个
访问冲突异常cannot be caught .
或
- 在进入未处理的
Run方法之前还有一些其他异常。为了验证这一点,请确保您的调试器 stops on first chance exceptions .
如果您指定:
也会有帮助- 你怎么知道没有到达第一行?断点?输出?
- 当您希望输入此功能时会发生什么?您的申请是否存在?
- 您是否正在逐步调试?
