Edit:
I’m an idiot (thankfully). I was trying to run the VM’s Step() function from a thread while also supplying input to it’s stream outside the thread. Funkiness ensued. I unthreaded it and handled input blocking a different way and all is well.

I’m making an IDE (personal project) for a virtual machine I’ve implemented in C# (school project). Everything is beautiful except one single pinch point: I can’t get writing to the input stream for the VM to read later to behave as expected.
The question: Does anyone have some resources for me to pursue, or would be willing to help me pinpoint what I’m misunderstanding about two way IO via a single memorystream? I’ve read the docs and some outdated source code and am still at a loss. Tutorials I’ve seen are about one way writing/reading, not two way like I need.


Details for the intrepid:I have a memory stream, iStream, that I wrap in a StreamReader for the to VM read input from. In my IDE console, I can get the VM to wait for input, and I can write input to it, but the behavior is so bizarre I don’t even know where to begin.
Things I’ve tried
copying the bytes myself into the backing byte[] buffer I give to iStream on creation
using iStream.Write()
using a temporary StreamWriter to write to iStream for me
I’ve Flushed(), DiscardedBufferedData(), and played as many games with Position and SetLength() as I could think of and the results are usually the same: I can read long words/sentences just fine, but anything shorter than 8 characters of data causes very strange behavior.
If you want to communicate cross thread like that, you need Channels
ooo some crunchy reading too, thank you.


I have a MemoryConnection available here that might be useful for you. https://github.com/scalablecory/NetworkToolkit/
C# devs
null reference exceptions

source

Categories: .NetCodingTech