Fix workflows run from the command line not exiting upon completion #1755
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Submitted as a draft since I want to double-check some things tomorrow morning and probably revisit the wording in the explanation comment.)
This issue was actually two different issues in a trench coat:
For a completely empty workflow (and perhaps other simple workflows?) the finally action will execute on the main thread, which causes
Application.Exit
to be called beforeApplication.Run
which means it doesn't exit.The second scenario is a workflow that end naturally and has a visualizer enabled. (Example workflow)
In this case the finally action will execute on a background thread.
Application.Exit
invokesFormClosing
andFormClosed
event handlers directly. This means those handlers are invoked off the main thread, which upsets manyFormClosed
handlers within Bonsai.As an added treat, any exceptions thrown from finally actions are swallowed unceremoniously. As a result, one of the many unhappy
FormClosed
handlers interruptsApplication.Exit
and the signal to exit the message pump never reaches the main thread.As a helpful side-effect, this means those exceptions are no longer ignored.
I also fixed the NotifyIcon getting leaked (which was the underlying clause of it hanging around when the application exited--which is what I assume the old explicit hide was trying to prevent.)
As an aside, I noticed
Observable.Finally
is used all over within Bonsai to run dispose methods and such. It seems like it'd be a good idea to investigate that further and see if it's expected behavior from Rx.NET or maybe a bug.Fixes #1740