Saturday, May 2, 2015

Console.ReadLine() not working with .net Framework > 3.5

So I was tinkering with the code, and found out that if I add a sleep period at the beginning of the program, Console.ReadLine() actually reads the data sent during this sleep period, send it back to the master app, and then stops reading again :

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string text;
            System.Threading.Thread.Sleep(3000);
            while (true)
            {
                //Console.WriteLine("0");    // Tested with and without, no impact
                text = Console.ReadLine();
                Console.WriteLine("1");
                Console.WriteLine(text);
            }
        }
    }
}

Display on the master software is as follows :

Sending message :  "earlyPing
"
Receiving message :  "1
"
Receiving message :  "earlyPing
"
Sending message :  "ping
"
So it may be a clue for a .net expert


No comments:

Post a Comment