杀死进程,解决运行异常---让64位程序调用32位程序更流畅

   上一篇随笔中写过64位程序与32位程序(https://www.cnblogs.com/Heavystudio/p/11059033.html),最近开始正式在项目中大量实现了,但又出现了一个问题,

由于32位程序中还调用了大量dll,导致每次调用时启动与关闭时都拖泥带水,致使出现运行异常runtime error R6016 - not enough space for thread data,经尝试发现,

这个异常会随运行内存变化而变化,根本原因是因为多次调用32位程序后,导致没有内存空间创建新的进程。

  经查找资料显示,这个问题经常出现在由C、C++、Vb6等写的代码中,而像C#中有自动内存管理,所以一般不会出现此类问题。

64位程序如下:

process.Kill();立刻杀死一切由这个32位程序启动的进程,用一次,杀一次,不影响下次使用
static void Main(string[] args)
        {  //创建refpropPipe进程
 Process process = new Process();
            //将refpropPipe.exe放在与refprop64Hv相同路径下,相对路径引用
            process.StartInfo.FileName = @"C:\Users\Administrator\source\repos\refpropPipe\refpropPipe\bin\Debug\refpropPipe.exe";
             //process.StartInfo.FileName = "refpropPipe.exe";
            process.Start();
            double value = 0;
            //向refpropPipe发送调用信息,即查询输入变量值
            using (NamedPipeClientStream pipeClientStream = new NamedPipeClientStream("request"))
            {
                pipeClientStream.Connect();
                string input = Method + "," + FluidName + "," + InpCode + "," + Units + "," + Prop1 + "," + Prop2;
                using (StreamWriter writer = new StreamWriter(pipeClientStream))
                {
                    writer.WriteAsync(input);
                }
            }
            //接收refpropPipe返回的信息,即查询结果
            using (NamedPipeClientStream pipeClientStream = new NamedPipeClientStream("respose"))
            {
                pipeClientStream.Connect();
                using (StreamReader reader = new StreamReader(pipeClientStream))
                {
                    string val = reader.ReadToEnd();
                    value = Convert.ToDouble(val);
                }
            }
            //process.WaitForExit();
            //process.Close();
           //不在等待了,直接杀死进程,省得拖泥带水,快哉快哉
          process.Kill();
 
}

  

posted @ 2019-06-28 11:55  Heavyer  阅读(892)  评论(0编辑  收藏  举报