Modeless Dialog & Threading

I’m working in c++ and have a modeless dialog that is responsible for communicating with a thread (ui pulls updates from it - same lifespan as ui). When I close the dialog normally, I can shut the thread down cleanly. If I leave the dialog hanging and close Rhino, my thread doesn’t terminate properly. When OnDestoy() fires when closing down Rhino, it looks like it is forcing the thread to terminate and that creates leaks for me. OnDestroy() is also being called before OnUnLoadPLugin - I tried to do some handling in there, and also worked with threading calls in the ui (SwitchToThread(), Sleep(0), WaitForSingleObject), but no joy. I was wondering if there is a way to signal the dialog before it gets OnDestroy() called when Rhino shuts down? I need to be able to switch focus to the other thread so it can terminate cleanly.


My best guess is that you can use a CRhinoEventWatcher in your dialog to get notified with it’s OnCloseRhino virtual function.

Thanks Steve, somehow I missed that event. Unfortunately it also gets called after the window gets destroyed.

Is it important that your thread doesn’t leak? This is all happening during shutdown so the OS will properly deal with reclaiming memory.

In some ways, no (it’s just a couple of strings). I think it may be getting far enough to disconnect from the device which is my real concern - the thread is interfacing with an attached hardware device. I didn’t have any problems re-connecting to it even after the errors, so there’s that. I’ll have to look a little deeper next year. It may be ok with the minor leak, just hoping to smooth things out…
Have Happy New Year!