I have a windows forms application that at startup starts up a new thread with a socket connection that listens for clients.
When this socket receives a value from the client, this value should be used on the main parent thread, while the child thread keeps running the socket.
This is because:
- When the socket receives the value, it calls an eventhandler and a long chain of methods after that. These methods adds the received value to existing data structures and changes the UI.
- The object that I need to add this value to seems to be null within the child thread. So I guess I instead need to pass the value back to the parent thread - without stopping the child thread.
- Just returning the value form the thread don't seem to be a solution because this would stop the socket from running.
How can I pass a value from the child thread to the parent thread without stopping the child thread?