Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4106824
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:25:34+00:00 2026-05-20T21:25:34+00:00

Is there a way to wait when listener is finised writing to file. Right

  • 0

Is there a way to wait when listener is finised writing to file. Right now half of the data is cut off. I think its becouse TextWriterTraceListener dosent manage to write data to file before the application closes.

    static void Main(string[] args)
    {
        Stopwatch stopwatch = new Stopwatch();

        // Begin timing
        stopwatch.Start();

        try
        {
            Trace.Listeners.Add(new ConsoleTraceListener(false));

            Trace.WriteLine(" ");
            Trace.WriteLine(DateTime.Now);
            Trace.WriteLine("Starting application...");
            Trace.WriteLine("-----------------------------------------------------------");
            Trace.WriteLine("Elapsed ms | Task information");
            Trace.WriteLine("-----------------------------------------------------------");
            Console.ForegroundColor = ConsoleColor.Green;

            foreach (int i in Enumerable.Range(1, 3))
            {
                Trace.WriteLine("Keypair nr: " + i);
                Trace.WriteLine(stopwatch.ElapsedMilliseconds + "ms | Starting to generate bytes for wrapping key..");
                byte[] keyBytes = generateKeyBytes();
                Trace.WriteLine(stopwatch.ElapsedMilliseconds + "ms | ..generation finished.");
                Trace.WriteLine(stopwatch.ElapsedMilliseconds + "ms | Executing java to generate private and public keys..");
                string keysString = runJava(keyBytes);
                Trace.WriteLine(stopwatch.ElapsedMilliseconds + "ms | ..generation finished.");
                string[] keys = keysString.Split(',');

                byte[] pubKey = Convert.FromBase64String(keys[0]);
                byte[] wrappedKey = Convert.FromBase64String(keys[1]);

                Trace.WriteLine(stopwatch.ElapsedMilliseconds + "ms | Decrypting the private key..");
                byte[] privKey = Decrypt(wrappedKey, keyBytes);
                Trace.WriteLine(stopwatch.ElapsedMilliseconds + "ms | ..decryption finished.");

                Trace.WriteLine("Public Key:\n\r" + BitConverter.ToString(pubKey));
                Trace.WriteLine("Private Key:\n\r" + BitConverter.ToString(privKey));
            }
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Trace.WriteLine("From: " + ex.Source + ".\nDetail: "+ ex.Message);
        }
        finally
        {
            Trace.WriteLine("Total Elapsed time: " + stopwatch.Elapsed);
            stopwatch.Stop();
            Console.WriteLine("Any key to exit..");
            Console.ReadKey();
        }
    }

Added my code.
And in config file i have:

<system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener"
          type="System.Diagnostics.TextWriterTraceListener"
          initializeData="output.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>

The last byte array what is printed out is cut off and the lines from finnaly block are allso missing from the output.log but still they appear on the console.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:25:35+00:00Added an answer on May 20, 2026 at 9:25 pm

    The Trace and Debug classes have Flush, Close and AutoFlush members. You need to use at least one of them. That the ConsoleListener works without them is accidental.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there's a way to wait for a file to be
Is there a better way to wait for queued threads before execute another process?
Is there a way I can tell the browser to wait to start on
In Erlang is there any way that a message sender can wait on a
is there any way to set timer for the progress bar? for example wait
I'm curious if there is an efficient way to wait for the front page
Is there way to get file from windows xp command prompt? I tried to
Is there way to copy a file into Plone with WebDAV and have Plone
Is there a way to wait for hide function in a loop? I mean
Is there a way to implement wait(); (non-static method) in a static context. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.