Am I not allowed to access public member? (.net Sockets, Threading)

The following case:

I have a communication class that uses streamreader and streamwriter on a successful network stream (.net Sockets)

The Receiving part is running in a thread and works as intended.

For sending messages I have an public method that takes a string parameter and writes it with StreamWriter on the NetworkStream.

I tested this class in a standalone application with no issues. Both receiving and transmitting.

In my other application I need to run the communication class in a thread.

But when I want to access communication.Send("xxx"); , a Nullreference Exception gets thrown {"Object reference not set to an instance of an object."}

I guess I'm not allowed to invoke Send, because I'm not allowed to control the thread from the outside.

Is this assumption correct? How can I send stuff anyway. The communication class is not supposed to know any other classes, so there are no events it can subscribe to ?

I'm a bit lost on this

by Lausiv_Edisn via /r/csharp

Leave a Reply