Using R21… I’ve been playing with windows forms.
I wrote a loop in the form (and obviously wrote it wrong)…
I got into an endless loop where my pop up keeps appearing.
I closed dynamo, the pop up is still going.
I close Revit - the pop up will not die!
I had to use task manager to kill the bloody thing!
When you create a winform you’re creating a sub-process (endlessly) in the context of Revit.
While you may have closed the Revit window, that doesn’t mean the Revit process ends. You can do a standard shutdown of Revit and watch the list of things disappear from task manager over time as a test. Another test is to try and close Revit while Dynamo isn’t saved; I often get ‘no sign’ of Revit or civil 3d on any monitor while I have a popup asking me if I want to save an unsaved .dyn.
Because the thread of your window is either a child of the parent Revit process, or a part of the Revit process, while that code is executing Revit can’t shut down all the way. And because your winform never ends the parent process can never close completely. Every other aspect of the UI might be gone, but not the parent.
Starting with a joking answer… Or when looking at it the other way… you guys need to add a break function to your winform.
The serious answer though is this: Forcing loops to break by a cancel button is not something anyone wants. Stability and data fidelity are shot by introducing such a “feature”, and while 1% of users might want a ‘cancel’ button, 99% of users don’t want the data they’re working hard to produce to be corrupted (note that the 1% changed their mind once they were told what that would mean), and 110% of users don’t want applications to crash. So until that’s resolved (likely many many many many years from now) I’m fine with the disconnect. And I say this as someone who’d greatly benefit from that button.
Add a circuit breaker to your loops when testing. This can be done by using an and condition in your loop condition and then using += 1 to it on each iteration. If the breaker exceeds the counter, the and check fails and you’re safe.
Example (with ‘True’ being your main condition):
breaker = 0
while True and breaker < 5:
breaker += 1
print('looping')
Lessons are only worthwhile if I remember them…
I’ve messed up loops so many times I’m pretty sure that bit of storage in my brain is used for something more fun.
Ha! I think you yourself might be in an infinite loop!
Unfortunately, this is just a lesson you will have to learn (eventually! )… Everyone learns the hard way with while loops, it’s usually that face-palm moment when you realise you forgot to add the break after 5 mins of running and you have to nuke your app with task manager. Do that enough times and you will remember…
Maybe a visual reminder on the wall next to your desk might help…