StdLinkLink Property

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

Definition

Namespace: Wolfram.NETLink
Assembly: Wolfram.NETLink (in Wolfram.NETLink.dll) Version: 2.0.0.0
C#
public static IKernelLink Link { get; set; }

Property Value

IKernelLink

Remarks

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

Example

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

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

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 the Wolfram Language, as then the property will be set automatically). One reason to set Link yourself is if you have classes that call the Wolfram Language that you want to use in both a standalone program and scripted from the Wolfram Language. For scripted uses, they need to use the Link property to get the link back to the Wolfram Language. 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 the Wolfram Language.

See Also