0

I've developed a C# program which I'm using as a child process of a parent process ( which is written in a different programming language than C#, namely: Smallworld Magik ). Standard I/O Channels to the C# program are used to communicate.

The meaning is to communicate with the C# program from the Smallworld Magik process. So, the C# program should receive commands from the Smallworld Magik process, and the Smallworld Magik process should receive the results/updates of the C# program.

The C# program initially receives the arguments by the main method of the program. The C# program writes the results/updates to the Output Channel and the Smallworld Magik process receives and handles them.

No problems till here.

The problem is located in receiving input commands from the Input Channel ( System.Console.In ) by the C# program. I'm using the System.Console.ReadLine() method to get the input command. Calling this method blocks further Program execution.

Does someone have a "non-blocking" solution to this? Since I'm a rooky C# developer, keep it low-level :).

dotnick
  • 3
  • 1
  • You could try this: http://stackoverflow.com/questions/57615/how-to-add-a-timeout-to-console-readline – Blorgbeard Feb 13 '12 at 13:18
  • What do you mean with "block"? Because when you use a ReadLine() the c# program will wait a input data, is this that you call to "block"? Or when you read the data with the ReadLine() the programs stop to work? – Vinicius Ottoni Feb 13 '12 at 13:27

1 Answers1

0

You could use Threading, and since you say you're a rooky i'm gonna direct you to the tutorial because threading is tricky and you should know what you're doing: http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx

Next thing you do is create a seperate thread for the ReadLine and invoke the result back to the main thread. Like this:

void Start()
{
    Thread T = new Thread(ThreadMethod);
    T.IsBackground = true;
    T.Start();
}

void ThreadMethod()
{
    string s = System.Console.ReadLine();

    this.Invoke(DoStuffInMain, s);
}

void DoStuffInMainThread(string s)
{
    //
}
hcb
  • 8,147
  • 1
  • 18
  • 17