C
C#4d ago
eid

await in c#

i can't understand await in c#, can u explain it with short words
16 Replies
Angius
Angius4d ago
This thing take long time, await the completion of that thing, in the meantime do other stuff
Xour
Xour4d 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
Angius4d ago
Yes, the current code will be halted, but the thread will be freed for anything else that needs it
eid
eid4d 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
Angius4d 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ΣX4d 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 User3d ago
Message Not Public
Sign In & Join Server To View
exixt
exixt3d ago
Asynchronous programming - C#
An overview of the C# language support for asynchronous programming using async, await, Task, and Task
exixt
exixt3d 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 User3d ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
I disagree, the article seems well suited to explaining asynchronicity.
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
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 User3d ago
Message Not Public
Sign In & Join Server To View
SleepWellPupper
That's just like, your opinion, man.
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts