有没有一种方法可以更快地在C#中打开Python脚本?
我想在C#应用程序中嵌入Python脚本。我有两个示例代码,但问题是这些脚本的加载速度非常慢有没有一种方法可以更快地在C#中打开Python脚本?,python,c#,embed,Python,C#,Embed,我想在C#应用程序中嵌入Python脚本。我有两个示例代码,但问题是这些脚本的加载速度非常慢 using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; namespace App { public class Test { private void runScript() { run_cmd(
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
namespace App
{
public class Test
{
private void runScript()
{
run_cmd();
}
private void run_cmd()
{
string fileName = @"C:\Users\d4wt0\Desktop\pracka\test_embedding\track.py";
Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Users\d4wt0\AppData\Local\Programs\Python\Python38\python.exe", fileName)
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output);
Console.ReadLine();
}
static void Main(string[] args)
{
Test t = new Test();
t.runScript();
Console.WriteLine(args.Length);
}
}
}
我不想用openCV、numpy等软件包打开几个脚本/函数,但以这样的速度是不可能的。第一次调用文件时速度这么慢是可以的,但是第二次我想更快一些。有没有办法做到这一点
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "C:/Users/Dawid/AppData/Local/Programs/Python/Python38/python.exe";
startInfo.Arguments = "file.py";
process.StartInfo = startInfo;
process.Start();