c#语言调用python,c#语言可以调用python程序问题

我在一个winform的c#程序里通过process调用python程序,这个python程序里有多线程。现在问题是我调用的python程序可以跑,但是跑一会就不能运行了,但是我如果单独运行python就没有问题,这是为什么。。` publ

ic void RunPythonScript(string path, string args = "")

{

path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "script\\" + path;

p.StartInfo.FileName = "python.exe";

string sArguments = "\"" + path + "\"";

if (args.Length > 0)

{

sArguments += " " + args;

}

//p.StartInfo.WorkingDirectory = "D:\\";

p.StartInfo.Arguments = sArguments;

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.RedirectStandardInput = true;

p.StartInfo.RedirectStandardError = true;

p.StartInfo.CreateNoWindow = true;

p.Start();

//p.CloseMainWindow();

//p.WaitForExit();

}`

把下面的这行代码取消注释就可以了。前提你这个操作是在主线程之外。不然会阻塞。//p.WaitForExit();

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd20417.html

相关文章 Recommend

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值