private void InternalCallback(TaskHandle task, string taskName, var returnValue, TaskExitStatus exitStatus) { //Logging.Trace("Thread internal callback: " + this + ":" + this.Name); _running = false; //Logging.Trace("Unregistering thread: " + this + ":" + this.Name); ThreadManager.UnregisterThread(this); if (exitStatus == TaskExitStatus.UnhandledException) { _unhandledException = returnValue.Cast<Object>() as Exception; } else if (exitStatus == TaskExitStatus.CriticalError) { _unhandledException = new ExecutionEngineException(returnValue.NativeToString()); } if (Callback != null) { // TODO: Use the SIP thread pool to run this callback Callback(); } else { if (_unhandledException != null) { Console.WriteLine("An unhandled exception occurred in thread: " + this + ": " + _unhandledException + "\n" + _unhandledException.StackTrace); } } }