I have a method which starts a DispatcherTimer
that reads all messages from a System.IO.Pipes.NamedPipe
. Before the timer starts, I want to read the first message.
// Initiate the PipeClient
pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.In);
pipeClient.Connect();
//declare executionSymbol
var reader = new StreamReader(pipeClient);
string executionSymbol = reader.ReadLine();
//start reading the messages
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(100);
timer.Tick += async (sender, e) => {
// Empty the Pipe...
};
timer.Start();
This works fine so far, but just because i was curious i made this change.
//declare executionSymbol
using (var reader = new StreamReader(pipeClient)) {
string executionSymbol = reader.ReadLine();
}
I was not expecting it to have any practical change, but as it turns out, it crashes my Program as soon as the method is called. Why does this happen? Feel free to ask me for more information!