New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add article on threading #2568
base: develop
Are you sure you want to change the base?
Add article on threading #2568
Conversation
I see though that there is a section in |
This has been on the docs for a very long time: https://github.com/gui-cs/Terminal.Gui/blob/develop/docfx/articles/mainloop.md#threading Oh, I see your second comment now. Yeah, might make sense to give it more visibility, given this |
@@ -0,0 +1,51 @@ | |||
# Threading | |||
It is common for a developer to run one or more background tasks on a separate | |||
`Thread` (or `Task`). For example to periodically fetch data. If you want to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the "infinitive form" in API docs instead of the "impersonal you". The infinitive form of a verb is its basic, uninflected form, typically preceded by the word "to" in English. For example, "to eat," "to play," or "to learn." By using the infinitive form, the sentence becomes more concise and focuses on the action itself.
This would be rewritten as "To make changes to a View
from a background task, issue the change on the main Terminal.Gui Thread thread."
Miguel tends to write using the "impersonal you" form, so a lot of the old docs still use this. But I've worked hard to rid most API docs of it. Thanks.
I guess it's worth mentioning that Termital.Gui has it's own SynchronizationContext and it really depends on how this task is started. (Note: SynchronizationContext is just an abstraction over some kind of Scheduler. In case of Terminal.Gui it's a single UI thread message loop) Few examples with default System.Threading.Task:
Examples above show that the problem is that when using async machinery you can't always be sure whether you are on UI thread or not. Possible means to fix this:
I hope this helps someone understand it better |
@tznind did you see my change request? |
Yeah sorry, not had a chance to get back to this yet. Its on my todo list.
…On Wed, 10 May 2023, 05:33 Tig, ***@***.***> wrote:
@tznind <https://github.com/tznind> did you see my change request?
—
Reply to this email directly, view it on GitHub
<#2568 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHO3C5AAU2R5GWAP5QKXCQDXFMK7ZANCNFSM6AAAAAAXGQ5BNU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Often we encounter users who are using Threads but do not know about
Application.MainLoop.Invoke
. For example:#2562 (comment)
I have created an article to explain how to update main UI thread from a background task.
Note that this targets
develop
so current users should see it. We can cherry pick it intov2_develop
Pull Request checklist:
CTRL-K-D
to automatically reformat your files before committing.dotnet test
before commit///
style comments)