Dezzamondo
Dezzamondo

Reputation: 2318

c# How to stop console from displaying "..." whilst StreamWriter copies large amounts of data from a DataTable

I have a console app that takes hundreds of small files, puts them into a temporary DataTable and then copies the data to a single StreamWriter. That works fine.

However, the console output continually adds "..." during the StreamWriter copy process, which is a bit annoying.

Is there any way to turn this off, or just replace it with something else, suck as a blinking "."?

Here's a cut down version of the code being used:

            Console.WriteLine("Writing to TA_{0}", fileType);
            var streamMaster = new StreamWriter(Settings.WorkingDirectory + "TA_" + fileType, true);
            streamMaster.Flush();

            foreach (var tempFile in filesList)
            {
                var isZipped = tempFile.Contains(".gz");
                var dtTempFile = InternalUtils.GetTable(tempFile, isZipped);

                foreach (DataRow row in dtTempFile.Rows)
                {
                    if(dtTempFile.Rows.IndexOf(row) != 0) streamMaster.WriteLine(String.Join(",", row.ItemArray));
                }
                streamMaster.Write(dtTempFile.Copy());

                dtTempFile.Dispose();
            }

            streamMaster.Close();
            streamMaster.Dispose();
            Console.WriteLine("TA_{0} Complete", fileType);

The output looks a lot like this:

Console Output

Any ideas?

Upvotes: 0

Views: 74

Answers (2)

Hassan
Hassan

Reputation: 5430

For progress you could show Console animation for the purpose. Which deals with few symbol like | / slash etc. You could set cursor position to spin it like animation.

  Console.WriteLine("Writing to TA_{0}", fileType);
  using(var streamMaster = new StreamWriter(Settings.WorkingDirectory + "TA_" + fileType, true))
   {     
       streamMaster.Flush();
       int counter = 0;

       foreach (var tempFile in filesList)
       {
            ShowAnimation(++counter);
            var isZipped = tempFile.Contains(".gz");
            var dtTempFile = InternalUtils.GetTable(tempFile, isZipped);

            foreach (DataRow row in dtTempFile.Rows)
            {
                if(dtTempFile.Rows.IndexOf(row) != 0) 
                    streamMaster.WriteLine(String.Join(",", row.ItemArray));
            }
            streamMaster.Write(dtTempFile.Copy());
            dtTempFile.Dispose();
        }
    }
    Console.WriteLine("TA_{0} Complete", fileType);

ShowAnimation Method:

public void ShowAnimation (int counter)
{              
    switch (counter % 4)
    {
        case 0: Console.Write("/"); break;
        case 1: Console.Write("-"); break;
        case 2: Console.Write("\\"); break;
        case 3: Console.Write("|"); break;
    }
    Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
}

Upvotes: 1

Dezzamondo
Dezzamondo

Reputation: 2318

Turns out there was a function several layers in that did this...

        If m_intRecord Mod 1000 = 0 Then
            Console.Write(".")
        End If

I must have completely overlooked it! Whoops!

Upvotes: 0

Related Questions