Hi,
I have implemented a network protocol using AsyncStreamsText. This if course works asynchroneously.
However the communication is called from a console append I want the main thread to wait until the async protocol handling has finished.
What I tried was:
- the main thread starts the Async communication and the calls StartMessageLoop
- the Async thread/class sets a class variable "result as boolean" and has its async handling of events but when the communication ends it calls sets "results = true" and then calls StopMessageLoop
- the next statement in the main thread (after StartMessageLoop) checks for the variable "result"
In debug mode at least it seems I have a race condition because I receive a message that a string cannot be converted in a Boolean (caused by reading the result). The console app (in debug mode) also seems to stop randomly after this.
What would be the appropriate way (I would like to keep the async handling but keep the async handling outside my main thread / console app).
Thanks
I have implemented a network protocol using AsyncStreamsText. This if course works asynchroneously.
However the communication is called from a console append I want the main thread to wait until the async protocol handling has finished.
What I tried was:
- the main thread starts the Async communication and the calls StartMessageLoop
- the Async thread/class sets a class variable "result as boolean" and has its async handling of events but when the communication ends it calls sets "results = true" and then calls StopMessageLoop
- the next statement in the main thread (after StartMessageLoop) checks for the variable "result"
In debug mode at least it seems I have a race condition because I receive a message that a string cannot be converted in a Boolean (caused by reading the result). The console app (in debug mode) also seems to stop randomly after this.
What would be the appropriate way (I would like to keep the async handling but keep the async handling outside my main thread / console app).
Thanks