C# 如何从StreamWriter中清除以前的行?

C# 如何从StreamWriter中清除以前的行?,c#,streamwriter,C#,Streamwriter,“build.txt”包含要编译以生成DLL文件的所有文件。对我来说,这就是答案。我只是用另一种方式做的,虽然可能没那么好 void readFromBuild() { doneReading = true; lines = System.IO.File.ReadAllLines(@"D:\PIT\ProcessImprovementTool\Build\build.txt"); //System.Console.WriteLine("Contents of WriteL

“build.txt”包含要编译以生成DLL文件的所有文件。

对我来说,这就是答案。我只是用另一种方式做的,虽然可能没那么好

void readFromBuild()
{
    doneReading = true;
    lines = System.IO.File.ReadAllLines(@"D:\PIT\ProcessImprovementTool\Build\build.txt");
    //System.Console.WriteLine("Contents of WriteLines2.txt = ");
    foreach (string line in lines)
    {
        lineCount++;
    }
    Console.WriteLine(lineCount);
    lineCount = lineCount - limit;
}
buildProgress.Enabled=true;
buildProgress.max=行数;
对于(int-ctr=0;ctr
这是什么“行”?我没有在你的代码中找到它!是否要清除以前的所有行?还是最后一行?您可以使用(StreamWriter sw=new StreamWriter(fileToClear)){sw.Write(“”;}uhmm.)。。它实际上并没有存储在文件中。。如果你的应用程序挂起,我会编辑它,这是因为控制台目前没有读取stdin,而你填充了缓冲区。您将无法及时返回并撤消已写入的数据。您所能做的就是设置一些东西,以便最终使用您的输入。但是你没有提供一个能可靠地再现你的问题的好方法,所以没有办法按照书面形式回答这个问题。@PeterDuniho。。看看“ctr”。。如果超过30,我想大概是40左右。。它挂着。。但如果低于30。。它运行得很好。。
for (int ctr = 0; ctr < 5; ctr++)
{
    sw.WriteLine("msbuild /property:OutputPath=" + outputPath + @";OutputType=Library " + lines[ctr]);
    //console.BeginOutputReadLine();
    sw.Flush();
}
void readFromBuild()
{
    doneReading = true;
    lines = System.IO.File.ReadAllLines(@"D:\PIT\ProcessImprovementTool\Build\build.txt");
    //System.Console.WriteLine("Contents of WriteLines2.txt = ");
    foreach (string line in lines)
    {
        lineCount++;
    }
    Console.WriteLine(lineCount);
    lineCount = lineCount - limit;
}
buildProgress.Enabled = true;
buildProgress.Maximum = lineCount;
for (int ctr = 0; ctr < lineCount; ctr++)
{   
    String outputPath = @"Q:\";
    StreamReader reader;
    String outputLine;
    console = new Process();
    console.StartInfo.FileName = "cmd.exe";
    console.StartInfo.UseShellExecute = false;
    console.StartInfo.CreateNoWindow = true;
    console.StartInfo.RedirectStandardInput = true;
    console.StartInfo.RedirectStandardOutput = true;
    console.StartInfo.RedirectStandardError = true;
    console.Start();
    using (StreamWriter sw = console.StandardInput)
    {
        sw.AutoFlush = true;
        console.StandardInput.AutoFlush = true;
        if (sw.BaseStream.CanWrite)
        {
            sw.WriteLine(@"Q:\");       
            sw.WriteLine("msbuild /property:OutputPath=" + outputPath + @";OutputType=Library " + lines[ctr]);
            sw.Flush();
        }
        sw.Close();
    }
    reader = console.StandardOutput;
    outputLine = reader.ReadToEnd();
    console.WaitForExit();
    //if (console.HasExited)
    //{ 
        Console.Write(outputLine);
        //outputTextBox.Text += outputLine;
        pathToLog = @"Q:\" + fileList[ctr];
        File.Create(pathToLog).Dispose();
        File.WriteAllText(pathToLog, outputLine);
        buildProgress.Value = ctr;
        string[] readThatLog = File.ReadAllLines(pathToLog);
        foreach(string line in readThatLog)
        {
            if (line == "Build succeeded.")
            { 
                outputTextBox.AppendText(lines[ctr]);
                outputTextBox.AppendText(Environment.NewLine + line);
                outputTextBox.AppendText(Environment.NewLine + Environment.NewLine);
            }
            else if (line == "Build FAILED.")
            {
                outputTextBox.AppendText(lines[ctr]);
                outputTextBox.AppendText(Environment.NewLine + line);
                outputTextBox.AppendText(Environment.NewLine + Environment.NewLine);
            }
        }
    //}
}
buildProgress.Value = 0;
buildProgress.Enabled = false;
Console.WriteLine("\n\n\n\nDONE!!!");