I've create a dummy communication between two processes, I cannot simulate your case due to the QT dependency. The ReadLine is worked as expected, the Threading that you applied maybe is showing a sync issue between the sender and the receiver but I'm not sure of that, it needs more investigation. Did you try to apply the Sleep inside the loop but will less than 3 second maybe 2ms=200?
The code that I worked on:
Sender:
static void Main(string[] args)
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"MypathtoReceiver\ReadLineReceiver.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
// Prompt the user for input text lines to sort.
// Write each line to the StandardInput stream of
// the sort command.
String inputText;
int numLines = 0;
do
{
inputText = Console.ReadLine();
if (inputText.Length > 0)
{
numLines++;
myStreamWriter.WriteLine(inputText);
}
} while (inputText.Length != 0);
}
Receiver:
static void Main(string[] args)
{
string text;
System.Threading.Thread.Sleep(3000);
while (true)
{
Console.WriteLine("Waiting for input...");
text = Console.ReadLine();
Console.WriteLine("Received Successfully: " + text);
Console.WriteLine("Sending Back: " + text);
}
}
Result:
Fouad Roumieh
No comments:
Post a Comment