.NET/Link API Version 1.7 USE FRAMES

StdLink.Link Property

Gets or sets the link that points back to the Mathematica kernel.

[Visual Basic]
Public Shared Property Link As IKernelLink
[C#]
public static IKernelLink Link {get; set;}

Remarks

When called during a session when .NET is "installed" into Mathematica (i.e., InstallNET[] has been called), this property gives the IKernelLink that points back to Mathematica. It returns null if .NET is not being used from Mathematica. .NET methods need to obtain the link back to Mathematica in a number of circumstances, such as if they want to return a result to Mathematica manually, or trigger computations in Mathematica before they return, or if they are called from the user interface in response to a user action like clicking a button.

Here is an example of how it might be used in a method that wants to return a result to Mathematica manually, instead of having its normal return value sent back.

IKernelLink ml = StdLink.Link;
if (ml != null) {
    ml.BeginManual();
    // Here we put a result to Mathematica manually:
    ml.Put(42);
}

Do not forget to call RequestTransaction on the link if you are calling back to Mathematica in response to some user action initiated in .NET (like clicking a button).

You might want to set this property yourself in a .NET program that launches and controls the kernel (that is, not a program that is itself called from Mathematica, as then the property will be set automatically). One reason to set Link yourself is if you have classes that call Mathematica that you want to use in both a standalone program and scripted from Mathematica. For scripted uses, they need to use the Link property to get the link back to Mathematica. If you set this property to be the link you have created in your standalone program, then your classes will automatically acquire the correct link in both cases. In other words, .NET/Link lets you assign the "StdLink" yourself, so that you don't have to modify all the code that calls StdLink.Link just to use that code in a program that is not being called from Mathematica.

See Also

StdLink Class | Wolfram.NETLink Namespace | RequestTransaction