C
C#5mo ago
eid

✅ await in c#

i can't understand await in c#, can u explain it with short words
18 Replies
Angius
Angius5mo ago
This thing take long time, await the completion of that thing, in the meantime do other stuff
Xour
Xour5mo ago
Isn't await the completion of that thing without blocking the main thread? Unless you do Task.Run the code will be halted, isn't that correct?
Angius
Angius5mo ago
Yes, the current code will be halted, but the thread will be freed for anything else that needs it
eid
eidOP5mo ago
result=task<int>.exception vs result=await method why the exception result is diffrent? await return normal exception ,but task.exception return another exception type(aggregation exception)
Angius
Angius5mo ago
There's no "vs" here Two completely different things Task.Exception gets you the exception that caused a given task to end prematurely, or null if the task did not end prematurely await Method() (assuming async Task Method()) will await the completion of the task returned from that method, freeing the thread to do other work in the meantime FWIW, as a general rule, you should just be awaiting your async task methods Don't try to handle the exceptions manually, don't try callbacks, none of that
DΣX
DΣX5mo ago
the await keyword, followed by anything which results in a task, will wait then for the completion of that task before continuing hence the task is being awaited
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
exixt
exixt5mo ago
Asynchronous programming - C#
An overview of the C# language support for asynchronous programming using async, await, Task, and Task
exixt
exixt5mo ago
@eid for more in depth about this please look at the link I sent, if you're looking at async await then that article is basically a requirement. you need to understand the concepts in more detail
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
SleepWellPupper5mo ago
I disagree, the article seems well suited to explaining asynchronicity.
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
SleepWellPupper5mo ago
It explicitly states that there is no parallelism involved in the example model:
Cooking breakfast is a good example of asynchronous work that isn't parallel.
and
For a parallel algorithm, you'd need multiple cooks (or threads).
looking at the three diagrams I can see no paralellism involved
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
SleepWellPupper5mo ago
That's just like, your opinion, man.
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
TcoUpLoad
TcoUpLoad4mo ago
I want to change backgroundworker with async/await. In my current scenario i had a backgroundworker declared in the controller. it has two method dowork and RunWorkerCompleted there. So my UI has call controller function that call backgroundworker.RunWorkerAsync().. how i change all this to async/await ?
SleepWellPupper
SleepWellPupper4mo ago
Please start your own topic/thread, reviving stale issues with new questions is not recommended.
Want results from more Discord servers?
Add your server