© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
22 replies
Claudiu HBann

C# Tasks question

hello, idk if this is the right place to ask but i have a question about how the tasks in c# work, like, let's say we have an application with an GUI and on an event on a button click I await a task that it will take about 2-3 seconds, but the GUI doesnt freeze and it works just fine, the question is how, because I am wating for that task to finish on the UI thread and it should freeze.

As an example I have some experience with C++/WinRT WinUI3 and for something like this to work you need to switch the context with
winrt::resume_background()
winrt::resume_background()
and now you are on a thread from a thread pool, you do your job and next you switch back on the UI thread with
winrt::resume_foreground(context)
winrt::resume_foreground(context)
, the context must be the one captured before resuming to the background or use the UI dispatcher to run something on the UI thread

There is a list of tasks and my task goes there and somewhere in time it runs on the UI thread too? the task contains multiple small tasks and are each of them go in the "list" one by one?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Question regarding tasks
C#CC# / help
2y ago
Basic C# question
C#CC# / help
5mo ago
C# Dictionary question
C#CC# / help
2y ago
C# Exit question
C#CC# / help
3y ago