vs-threading
vs-threading copied to clipboard
Add a NoThrowAwaitable for SwitchToMainThreadAsync
It will be easier to avoid first chance exceptions if a NoThrowAwaitable extension method can be added for MainThreadAwaitable. The Boolean result of this custom awaitable would be true if the continuation executes on the main thread, and false if the continuation happened on any other thread.
💭 Should the method return a value indicating the current thread (true=main thread; false=other thread), or return a value indicating whether cancellation is requested (true=main thread and not cancelled; false=cancelled).
I suppose it should be whether canceled or not, since folks seem mostly interested in whether to continue based on cancellation rather than whether they landed on the main thread before cancellation was processed (or were already there before they asked to switch).
But I wonder in that case whether you need to return bool at all. The caller obviously already has a token they can check.
If we keep the void result for the awaiter, I can merge this feature directly into the existing MainThreadAwaitable without making new awaitables (since GetResult() would keep the void return value).