Can you await a Task and return Task<bool> (with a constant bool value) without the `await` keyword?
I came up with this code which does what I want:
but the problem is that the
t => true
part ends up being executed on a worker thread, even if myTask
is completed (e.g. status is RanToCompletion). Is there a proper way to do this without checking if myTask
is completed?23 Replies
Why don't you want to use await?
Trying to reduce how much I use it because it makes the stack frames really messy
is that still a thing nowadays?
Still uses await though 😦
you can't avoid using await 😬 if you use ContinueWIth you get even worse problems
I guess I could just do
return myTask.IsCompleted ? Task.FromResult(true) : myTask.ContinueWith(t => true)
... still kinda messy though but at least it worksare you using a modern .NET version? I also like to avoid Exceptions as much as possible
.NET Standard 2.0
that was resolved years ago, what is your tooling setup?
What's that?
do not try and re-invent awaiting, it's not trivial
whatever is giving you "messy" stack traces
You mean IDE? I'm using rider
this is what I mean by messy stack trace though
...what would you expect it to look like? That is everything that a stack trace should be
Would prefer it without the purple lines 😛
it shows the logical chain of calls that brought you to where you are now
because those things aren't your code?
that's a UI issue, there's a setting for that
Well more that it's just filler stuff that doesn't tell me much apart from that it's an async method
I wish there was 😦
I think i'm just gonna switch back to async, the code just looks better apart from the stack trace
there is in VS
Rider Support | JetBrains
Rider Debugger shows external call stack frames as just "[External ...
At some point in the last year, the new "[External code: n frames]" format started appearing in this call stack window in the debugger.
IIRC, before this, you could at least see the names of the me...
Visual studio's stack trace window is pretty much unintelligible anyway, just looks like a mush of the same colour text
the fix is to hide the purple lines, not mess up your code
or to use tools for async debugging like https://www.jetbrains.com/help/rider/Debugging_Multithreaded_Applications.html
JetBrains Rider Help
Debug multithreaded applications | JetBrains Rider
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.