主要内容

MathWorks.MATLAB.Runtime.OutOfProcessAttribute

.NET 属性类用于启动单独的进程来运行 .NET 程序集

自 R2022b 起

描述

使用 OutOfProcess 属性可以启动单独的进程来运行 .NET 程序集。

程序集

C:\Program Files\MATLAB\R2025b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Runtime.dll

C:\Program Files\MATLAB\R2025b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Types.dll

类详细信息

命名空间:

MathWorks.MATLAB.Runtime
超类:System.Attribute

构造

如果 tf 设置为 true,则 [assembly: OutOfProcess(tf)] 将启动一个单独的进程来运行 .NET 程序集。如果 tf 设置为 false,则 .NET 程序集将在同一进程中运行。默认情况下,OutOfProcess 设置为 false

参数

tf

布尔值 truefalse

C# 示例

using System;
using MathWorks.MATLAB.Runtime;
using MathWorks.MATLAB.Types;
[assembly: Nojvm(true), OutOfProcess(true)]

namespace MyConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string ctfPath = @"P:\MATLAB\work\mylinspace.ctf ";
                using (dynamic matlab = MATLABRuntime.StartMATLAB(ctfPath))
                {
                    double[] vec = matlab.mylinspace(1.0, 100.0);
                    foreach (double i in vec)
                    {
                        Console.Write("{0} ", i);
                    }
                }
            }
            catch (MathWorks.MATLAB.Exceptions.MATLABNotAvailableException)
            {
                Console.Error.WriteLine("Could not start MATLAB Runtime.");
            }
            MATLABRuntime.TerminateApplication();
        }
    }
}

版本历史记录

在 R2022b 中推出