I’m writing a websockets component. All the work needs to be done in a separate thread due to the way the System.Net.WebSockets.ClientWebSocket code works. It’s all task based. When I receive a message from the websocket I call ExpireSolution(true) but sometimes that is causing an exception to be thrown
However the ExpireSolution line is what is triggering the exception from Grasshopper. I would assume there is some kind of way to dispatch a call back to the main thread like in WPF though I can’t find it.
This works fine. However, when I right click on the canvas and tell Grasshopper to Recompute, then an exception is thrown. The runtime doesn’t like a second webSocket.ReceiveAsync() to be run in parallel. This makes sense. One approach is to first stop the current task, but there I also ran into issues. Did you encounter this problem, and did you solve it?
Update: Solved the issue by introducing a variable receivingMessage that indicates whether the component is currently receiving a message. If that is the case, if will not start receiving another message in parallel.