필터 지우기
필터 지우기

Initializing MATLAB runtime from c# app

조회 수: 32 (최근 30일)
Chase
Chase 2023년 6월 30일
편집: Chase 2023년 7월 6일
I have a c# windows form app that launches standalone MATLAB exes built with compiler.build.standaloneApplication. However launching these exes takes quite a long time since MATLAB runtime needs to be initialized (30 seconds to minutes for some apps). Is there a way I can preload the runtime when the c# app is launched to reduce subsequent launch times of the standalone apps?

답변 (1개)

Prannoy
Prannoy 2023년 6월 30일
Yes, you can preload the MATLAB Runtime when your C# app is launched to reduce subsequent launch times of the standalone MATLAB apps. Preloading the MATLAB Runtime ensures that it is initialized and ready to be used by the standalone apps when they are launched.
Here's an example of how you can preload the MATLAB Runtime in your C# app:
  1. Add a reference to the MathWorks.MATLAB.NET.Arrays assembly in your C# project.
  2. In your C# code, before launching the standalone MATLAB app, you can preload the MATLAB Runtime by creating an instance of the MathWorks.MATLAB.NET.Utility.MWMCR class and calling the Initialize method. This initializes the MATLAB Runtime and reduces the subsequent launch times of the standalone apps.
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
// Preload the MATLAB Runtime
MWMCR mcr = new MWMCR();
mcr.Initialize();
3. After preloading the MATLAB Runtime, you can launch the standalone MATLAB app as usual.
  댓글 수: 1
Chase
Chase 2023년 6월 30일
편집: Chase 2023년 7월 6일
@Prannoy Thanks for your response. When trying to create an instance of MWMCR, I get this error
Note: THIS CONSTRUCTOR SHOULD ONLY BE REFERENCED FROM COMPILER GENERATED CODE.
CS1729: 'MWMCR' does not contain a constructor that takes 0 arguments
I have a reference to MWArray in my project ( C:\Program Files\MATLAB\MATLAB Runtime\<version>\toolbox\dotnetbuilder\bin\win64\<framework_version>\MWArray.dll )

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB Compiler SDK에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by