honey the codewitch
honey the codewitch
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
The whole serial port business is a mess too. I wish .NET was more consistent about its asynchronous APIs
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
i was just hoping there was an elegant, efficient, Task based solution to situations like this
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
it smells bad to me to spin another thread when i'm waiting on the primary thread doing nothing when i could be polling on the primary thread
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
yeah your solution is flexible, but it's also a bit heavy handed for just monitoring a keypress. like my current solution is
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
can i wrap a task using another TaskCompletionSource<> and add a Console.KeyAvailable poll in there somehow? hmmm
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
i wonder
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
the only thing I don't like about that is the mess
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
if i wasn't using await i could poll using while(!Console.KeyAvailable && !task.IsCompleted) or whatever
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
basically as i said to someone else above, it's really await that hamstrings me here
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
my concern here is partly efficiency. anyone can turn a poll into an event by spinning a thread, but is that really necessary in this case? I don't think it is
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
i'd almost rather avoid Task.Run as much as new Thread, and maybe ditch await, and poll the tasks for completion to avoid spinning up another thread
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
only thing about that @maxmahem is it's doing what i'm doing, but with extra steps
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
actually awaiting the input stream is more ideal for my scenario. that's a good idea
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
if such a thing exists
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
i want something as efficient, but cleaner than that
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
the thing is, await is what's really hamstringing me here. If I was just polling the task for completion in a loop, I could check for keypress in the polling loop and set the cancelation token.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
there are a lot of situations where I could end up in a similar predicament, and I'd love to know the best way to handle it, because this isn't it
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
yeah, well consider this a training exercise in using tasks and cancelation tokens - at least that's what I'm treating it as
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
I'm trying to break on an arbitrary keypress in this case
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
i'm not trying to handle the Ctrl+C event
45 replies