Lorenz Cuno Klopfenstein

Articles from February 2009

Yesterday I passed the exam in Logic Programming: a very interesting declarative programming style based on the foundations of mathematical logic.

Take this as a short, very vague, introduction: logic programming works by defining some logic clauses in your program and then applying a resolution algorithm on a particular query (the logical clause you are trying to "prove" according to logic inference rules). The logic interpret will then determine whether your query is a logical consequence of the program or not, i. e. the query is satisfied and a valid result was found.

More...

Posted on Thursday, February 05, 2009
301 Views
2 comments posted

While working on the XNA Contest I wanted to use a standard Windows Forms dialog for credits at the end of the game, instead of doing it all inside XNA (mostly because it would have been much easier and faster to do). At the moment, when the game is over, this dialog appears:

My game's credits

The problem is that, as soon as the XNA window closes and the game terminates, the XNA framework tears down the entire thread on which it was running. If you try to open a Windows Forms dialog at that point, you will see a glimpse of it for some millisecond if you're lucky.  :)

The solution is a pretty simple workaround, but since I tried a lot of different things before and wasted some time, I thought this might by interesting to share: essentially, you run the whole XNA game in a different thread than your main thread. When XNA closes its window, it will tear down the other thread you created, leaving you with the main thread still running.

static void Main(string[] args) {

	Application.EnableVisualStyles();

	//Separate thread on which the game will run
	Thread backThread = new Thread(new ThreadStart(delegate() {
		using (Main game = new Main()) {
			game.Run();
		}
	}));

	backThread.Start();

	//Wait for the game to end
	backThread.Join();

	//Credits dialog
	using (Credits c = new Credits()) {
		c.ShowDialog();
	}
}
Posted on Wednesday, February 11, 2009
949 Views
54 comments posted
Back to Klopfenstein.net
Clemens Klopfenstein Serena Kiefer Lukas Tiberio Klopfenstein Lorenz Cuno Klopfenstein
English German