I am writing a chess game which allows two programs compete, the player needs to write a DLL and expose a function to tell the main application where his player will move next, suppose the function looks like this

public static void MoveNext(out int x, out int y, out int discKind);

The player's DLL can be written using C# or C++.

In the chess game application, I start a new thread to call the function that the player's DLL exposed to get where he will move in a turn, and I start a timer to prevent the player timeouts, if a player timesout i will kill the corresponding thread by following APIs

thread.Abort();
thread.Join();

I have the following issues as described below:

  1. The thread cannot be killed with 100% assurance (it depends on the player's code)

  2. During test I found that, if the player uses a deep recursions (and if there is memory leak in the player's program), the memory usage of the host application will increase and then the host application will be terminated without any exceptions.

Are there any techniques, ideas or methods that can handle the above issues?

From this CodeInChaos suggested to load player's DLL into separate domain and then unload it when necessary, I am not sure if it still works for the unmanaged DLL (C++) and if it will cause a low efficiency?

Accepted Answer

An unhandled exception in their AppDomain will still cause your program to terminate in .Net 2.0. You get a chance to respond to the exception through an event handler but not the ability to handle it.

Your best bet is to use processes for the kind of isolation you're looking for.

Written by SuperIronBob
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki