【发布时间】:2013-09-11 20:24:57
【问题描述】:
我有一个使用 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();
}
}
【问题讨论】:
-
在
Game.Run()上添加一个断点并进入它。它是“正确的”运行方法吗?调用Environment.Exit的不正确/陈旧的 Run 方法可能会终止进程而无异常。
标签: c# .net debugging visual-studio-debugging sfml