<bdo id='z55Dd'></bdo><ul id='z55Dd'></ul>

<small id='z55Dd'></small><noframes id='z55Dd'>

  • <i id='z55Dd'><tr id='z55Dd'><dt id='z55Dd'><q id='z55Dd'><span id='z55Dd'><b id='z55Dd'><form id='z55Dd'><ins id='z55Dd'></ins><ul id='z55Dd'></ul><sub id='z55Dd'></sub></form><legend id='z55Dd'></legend><bdo id='z55Dd'><pre id='z55Dd'><center id='z55Dd'></center></pre></bdo></b><th id='z55Dd'></th></span></q></dt></tr></i><div id='z55Dd'><tfoot id='z55Dd'></tfoot><dl id='z55Dd'><fieldset id='z55Dd'></fieldset></dl></div>

      <legend id='z55Dd'><style id='z55Dd'><dir id='z55Dd'><q id='z55Dd'></q></dir></style></legend>
    1. <tfoot id='z55Dd'></tfoot>

        控制台应用程序中的进度条

        时间:2023-08-27
        • <bdo id='2wZ0n'></bdo><ul id='2wZ0n'></ul>
          <legend id='2wZ0n'><style id='2wZ0n'><dir id='2wZ0n'><q id='2wZ0n'></q></dir></style></legend>
          <tfoot id='2wZ0n'></tfoot>
        • <small id='2wZ0n'></small><noframes id='2wZ0n'>

              1. <i id='2wZ0n'><tr id='2wZ0n'><dt id='2wZ0n'><q id='2wZ0n'><span id='2wZ0n'><b id='2wZ0n'><form id='2wZ0n'><ins id='2wZ0n'></ins><ul id='2wZ0n'></ul><sub id='2wZ0n'></sub></form><legend id='2wZ0n'></legend><bdo id='2wZ0n'><pre id='2wZ0n'><center id='2wZ0n'></center></pre></bdo></b><th id='2wZ0n'></th></span></q></dt></tr></i><div id='2wZ0n'><tfoot id='2wZ0n'></tfoot><dl id='2wZ0n'><fieldset id='2wZ0n'></fieldset></dl></div>
                  <tbody id='2wZ0n'></tbody>

                  本文介绍了控制台应用程序中的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在编写一个简单的 c# 控制台应用程序,用于将文件上传到 sftp 服务器.但是,文件量很大.我想显示上传文件的百分比,或者仅显示要上传的文件总数中已上传​​的文件数.

                  I'm writing a simple c# console app that uploads files to sftp server. However, the amount of files are large. I would like to display either percentage of files uploaded or just the number of files upload already from the total number of files to be upload.

                  首先,我得到所有文件和文件总数.

                  First, I get all the files and the total number of files.

                  string[] filePath = Directory.GetFiles(path, "*");
                  totalCount = filePath.Length;
                  

                  然后我遍历文件并在foreach循环中一一上传.

                  Then I loop through the file and upload them one by one in foreach loop.

                  foreach(string file in filePath)
                  {
                      string FileName = Path.GetFileName(file);
                      //copy the files
                      oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
                      //Console.WriteLine("Uploading file..." + FileName);
                      drawTextProgressBar(0, totalCount);
                  }
                  

                  在 foreach 循环中,我有一个进度条,但我遇到了问题.无法正常显示.

                  In the foreach loop I have a progress bar which I have issues with. It doesn't display properly.

                  private static void drawTextProgressBar(int progress, int total)
                  {
                      //draw empty progress bar
                      Console.CursorLeft = 0;
                      Console.Write("["); //start
                      Console.CursorLeft = 32;
                      Console.Write("]"); //end
                      Console.CursorLeft = 1;
                      float onechunk = 30.0f / total;
                  
                      //draw filled part
                      int position = 1;
                      for (int i = 0; i < onechunk * progress; i++)
                      {
                          Console.BackgroundColor = ConsoleColor.Gray;
                          Console.CursorLeft = position++;
                          Console.Write(" ");
                      }
                  
                      //draw unfilled part
                      for (int i = position; i <= 31 ; i++)
                      {
                          Console.BackgroundColor = ConsoleColor.Green;
                          Console.CursorLeft = position++;
                          Console.Write(" ");
                      }
                  
                      //draw totals
                      Console.CursorLeft = 35;
                      Console.BackgroundColor = ConsoleColor.Black;
                      Console.Write(progress.ToString() + " of " + total.ToString() + "    "); //blanks at the end remove any excess
                  }
                  

                  输出只是 [ ] 0 out of 1943

                  The output is just [ ] 0 out of 1943

                  我在这里做错了什么?

                  我试图在加载和导出 XML 文件时显示进度条.然而,它正在经历一个循环.完成第一轮后进入第二轮,以此类推.

                  I'm trying to display the progress bar while I'm loading and exporting XML files. However, it's going through a loop. After it finishes the first round it goes to the second and so on.

                  string[] xmlFilePath = Directory.GetFiles(xmlFullpath, "*.xml");
                  Console.WriteLine("Loading XML files...");
                  foreach (string file in xmlFilePath)
                  {
                       for (int i = 0; i < xmlFilePath.Length; i++)
                       {
                            //ExportXml(file, styleSheet);
                            drawTextProgressBar(i, xmlCount);
                            count++;
                       }
                   }
                  

                  它永远不会离开 for 循环...有什么建议吗?

                  It never leaves the for loop...Any suggestions?

                  推荐答案

                  这行是你的问题:

                  drawTextProgressBar(0, totalCount);
                  

                  您是说每次迭代的进度都为零,这应该增加.也许改用 for 循环.

                  You're saying the progress is zero in every iteration, this should be incremented. Maybe use a for loop instead.

                  for (int i = 0; i < filePath.length; i++)
                  {
                      string FileName = Path.GetFileName(filePath[i]);
                      //copy the files
                      oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
                      //Console.WriteLine("Uploading file..." + FileName);
                      drawTextProgressBar(i, totalCount);
                  }
                  

                  这篇关于控制台应用程序中的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检测控制台应用程序何时关闭/终止? 下一篇:控制台应用程序 C# 中的 App.Config 文件

                  相关文章

                  最新文章

                  <legend id='3H5k9'><style id='3H5k9'><dir id='3H5k9'><q id='3H5k9'></q></dir></style></legend>
                • <small id='3H5k9'></small><noframes id='3H5k9'>

                    • <bdo id='3H5k9'></bdo><ul id='3H5k9'></ul>

                  1. <tfoot id='3H5k9'></tfoot>

                    1. <i id='3H5k9'><tr id='3H5k9'><dt id='3H5k9'><q id='3H5k9'><span id='3H5k9'><b id='3H5k9'><form id='3H5k9'><ins id='3H5k9'></ins><ul id='3H5k9'></ul><sub id='3H5k9'></sub></form><legend id='3H5k9'></legend><bdo id='3H5k9'><pre id='3H5k9'><center id='3H5k9'></center></pre></bdo></b><th id='3H5k9'></th></span></q></dt></tr></i><div id='3H5k9'><tfoot id='3H5k9'></tfoot><dl id='3H5k9'><fieldset id='3H5k9'></fieldset></dl></div>