C# StreamReader readLine()在读取JSON输出C的大行时挂起#

C# StreamReader readLine()在读取JSON输出C的大行时挂起#,c#,python,json,C#,Python,Json,我目前正在使用C#和StreamReader类从Python文件中读取StandardOutput,该文件以JSON格式检索服务器数据。用户可以输入一个搜索键(服务器名、IP、ID等),它将在下面返回此数据。用户还可以搜索尽可能多的服务器详细信息,有时多达1000个搜索键 示例: [{'Search': 'serverName', 'Name': 'test.testing.com', 'IP': '10.XXX.XXX.X', 'State': 'OK', 'OS': 'Windows',

我目前正在使用C#和StreamReader类从Python文件中读取StandardOutput,该文件以JSON格式检索服务器数据。用户可以输入一个搜索键(服务器名、IP、ID等),它将在下面返回此数据。用户还可以搜索尽可能多的服务器详细信息,有时多达1000个搜索键

示例:

[{'Search': 'serverName', 'Name': 'test.testing.com', 'IP': 
'10.XXX.XXX.X', 'State': 'OK', 'OS': 'Windows', 'ID':'123456'}]
我目前正在读取输出并将其添加到C代码中的列表中

输出都包含在一行中(不确定这是否是处理它的最佳方式),因此不需要循环。它可以很好地读取较小的输出,但是,当用户输入大量搜索键时,程序将挂起在sr.Readline()块上

每当我在终端中运行Python脚本时,无论搜索键数组有多大,我都能够相当快地检索JSON输出。有没有更好/更快的方法来处理从流中读取一大行JSON输出,而不会导致它挂起

提前谢谢

编辑:

下面是我的Python进程信息

pythonProcess = new Process();
    try
    {
        pythonProcess.StartInfo.FileName = filename;
        pythonProcess.StartInfo.RedirectStandardInput = true;
        pythonProcess.StartInfo.RedirectStandardOutput = true;
        pythonProcess.StartInfo.RedirectStandardError = true;
        pythonProcess.StartInfo.Verb = "runas";
        pythonProcess.StartInfo.UseShellExecute = false;
        pythonProcess.StartInfo.Arguments = "-u \"" + serverPath + "\\" + scriptName + "\"";
        pythonProcess.Start(); // start the process (the python program)            
    }
    catch (Exception e)
    {

    }

为什么不使用ReadLineSync?您的行必须非常大且异常大,才能挂起
StreamReader
。我从未经历过这样的事情,
StreamReader
非常快,因为它处理的是
。请您提供一个JSON字符串的示例,然后我可以运行一些测试并为您提供适当的解决方案。@rory.ap:Async无法解决问题,它仍然需要很长时间,只是它可以防止应用程序冻结。我想关键是要加快这个过程。@supernative--是的,我有点含糊不清,但我暗示的是1。)没有办法加快,也就是说,它就是它的本来面目,2。)你可以防止应用程序冻结,以便更方便用户使用。读取输出是非常重要的,许多因素都会导致你的进程或启动的进程死锁。例如,请参见:、和。阅读关于已接受答案的评论,你会发现它们甚至不是完美的,这取决于条件,但在这些问题中,你可以尝试20种不同的答案。
pythonProcess = new Process();
    try
    {
        pythonProcess.StartInfo.FileName = filename;
        pythonProcess.StartInfo.RedirectStandardInput = true;
        pythonProcess.StartInfo.RedirectStandardOutput = true;
        pythonProcess.StartInfo.RedirectStandardError = true;
        pythonProcess.StartInfo.Verb = "runas";
        pythonProcess.StartInfo.UseShellExecute = false;
        pythonProcess.StartInfo.Arguments = "-u \"" + serverPath + "\\" + scriptName + "\"";
        pythonProcess.Start(); // start the process (the python program)            
    }
    catch (Exception e)
    {

    }