我有一个c#console应用程序。
该程序非常简单。它只是打开一个Matlab应用程序&指定我想运行的m文件的目录,提供一个参数(代码如下)。 m文件中的代码基本上将一些数据上传到数据库。在此之后,将根据上载到数据库的数据创建Excel报告。
我将此任务安排在凌晨4点运行。该代码在前两个月运行良好。但是(我没有发现任何变化)代码无法正常工作。我早上来看它已经打开了一个matlab& amp;它已经改变了matlab目录,但它似乎没有运行matlab函数。奇怪的是,c#代码然后运行excel代码,然后重新编译数据库中没有数据。当我进入并手动运行代码虽然代码工作正常。我不知道发生了什么或如何找出发生了什么?
在计划的Windows中,任务有消息"操作成功完成。 (为0x0)
public void CalculateFundDrift()
{
try
{
// create matlab instance
_matlab = new MLApp.MLApp();
// change to the directory where the function is located
_matlab.Execute(@"cd c:\my_directory\");
// define the output
object result = null;
// call the matlab function upload_data
_matlab.Feval("my_func_name", 0, out result, "my_para");
// quit matlab
Console.WriteLine(Environment.NewLine + "Closing Matlab");
_matlab.Quit();
}
catch(Exception ex)
{
_matlab.Quit();
throw;
}
}
更新
运行代码时我没注意到的一件事是它打开了一个matlab命令窗口(看起来更像是一个文本文件)。早上,当我进入一个已经开放的实际matlab应用程序时。