.NET/Link API Version 1.5 USE FRAMES

IKernelLink.TerminateKernel Method 

Sends a request to the kernel to shut down.

[Visual Basic]
Sub TerminateKernel()
[C#]
void TerminateKernel();

Remarks

Most of the time, when you call Close on a link, the kernel will quit. If the kernel is busy with a computation, however, it will not stop just because the link closes. Use TerminateKernel to force the kernel to quit even though it may be busy. This is not an operating system-level "kill" command, and it is not absolutely guaranteed that the kernel will die immediately.

This method is safe to call from any thread. Any method that is blocking waiting for a result from Mathematica (such as WaitForAnswer) will return immediately and throw a MathLinkException. You will typically call Close immediately after TerminateKernel, as the link will die when the kernel quits.

A typical usage scenario is as follows. You have a thread that is blocking in WaitForAnswer waiting for the result of some computation, and you decide that it must return right away and you are willing to sacrifice the kernel to guarantee this. You then call AbandonEvaluation on a separate thread. This causes WaitForAnswer to immediately throw a MathLinkException. You catch this exception, discover that ClearError returns false indicating that the link is hopeless, and then you call TerminateKernel followed by Close. The reason TerminateKernel is useful here is that because you called AbandonEvaluation, the kernel may still be computing and it may not die when you call Close. You call TerminateKernel to give it a little help.

What this method does is simply use PutMessage to send a MathLinkMessage.Terminate to the kernel. It is provided as a convenience to shield programmers from such low-level details.

See Also

IKernelLink Interface | Wolfram.NETLink Namespace | AbortEvaluation | InterruptEvaluation | AbandonEvaluation