.NET/Link API Version 1.7 USE FRAMES

IKernelLink.HandlePacket Method 

Call this to invoke .NET/Link's internal handling of special packet types.

[Visual Basic]
Sub HandlePacket( _
   ByVal pkt As PacketType _
void HandlePacket(
   PacketType pkt


The packet type that was read using NextPacket.


If you absolutely must write your own packet loop instead of using the PacketArrived event, (this is strongly discouraged), you should call this method if a call to NextPacket returns a packet type that you are not handling entirely with your own code. In fact, you can call HandlePacket for every packet you read with NextPacket.

For example, here is a basic packet loop:

bool done = false;
while (!done) {
    PacketType pkt = ml.NextPacket();
    if (ml.OnPacketArrived(pkt))
    switch (pkt) {
        case PacketType.Return:
            // read and handle contents of ReturnPacket ...
            done = true;
         case PacketType.Text:
            // read and handle contents of TextPacket ...
        .. etc for other packet types

After HandlePacket returns you should call NewPacket.

To remind again, writing your own packet loop like this is strongly discouraged. Use WaitForAnswer, WaitAndDiscardAnswer, or one of the "EvaluateTo" methods instead. These methods hide the packet loop within them. If you want more information about what packet types arrive and their contents, simply use the PacketArrived event.

An example of the special type of packets that your packet loop might encounter is PacketType.Call. Encountering a PacketType.Call means that Mathematica code is trying to call into .NET using the mechanism described in Part 1 of the .NET/Link User Guide. Only the internals of .NET/Link know how to manage these callbacks, so the HandlePacket method provides a means to invoke this handling for you.

If you are using WaitForAnswer, WaitAndDiscardAnswer, or any of the "EvaluateTo" methods, and therefore not writing your own packet loop, you do not need to be concerned with HandlePacket.


Exception Type Condition
MathLinkException On any MathLink error.

See Also

IKernelLink Interface | Wolfram.NETLink Namespace