C
C#16mo ago
Lexa

❔ While loop stuck

Hey, someone has an idea why after running a method my while loop just stops ? thank you
12 Replies
Buddy
Buddy16mo ago
Tasks are not long-running unless you specify them to be
Angius
Angius16mo ago
(also, nice discarded task)
Lexa
Lexa16mo ago
is that ironic ?
Lexa
Lexa16mo ago
I'am doing this in an other method, could you explain why it does't work here ?
Angius
Angius16mo ago
For the time being, yes. Tasks should, generally, be awaited. But you might have reasons to fire&forget it, dunno
Lexa
Lexa16mo ago
so you have any idea how to solve my issue ? could use thread
Buddy
Buddy16mo ago
You can spawn a Thread instead of a Task, as you pretty much have no reason to use Task. for the first example
Lexa
Lexa16mo ago
why not the second one ?
mtreit
mtreit16mo ago
There's no particular advantage to using a Thread object instead of a Task object and Thread has a much less ergonomic API. Just use Task.Factory.StartNew with the TaskCreationOptions.LongRunning flag. (To avoid burning a thread pool thread unnecessarily)
Lexa
Lexa16mo ago
is it clean now ?
Lexa
Lexa16mo ago
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.