❔ ✅ (SOLVED) TcpListener.AcceptTcpClientAsync does not get cancelled
so i expect this code to accept any tcp clients and if a 400ms period pass it will cancel but for whatever reason AcceptTcpClientAsync keeps halting my execution! i could probably run my own wait timer and if the timer finishes then i will call TcpListener.Stop() but i can see how that workaround would cause issues for in the future.
and one odd thing is when a tcp client successfully connects to the server the function doesnt finish execution oddly
10 Replies
are u handling the cancellation exception?
cap5lut
REPL Result: Success
Console Output
Compile: 680.802ms | Execution: 506.433ms | React with ❌ to remove this embed.
im handling An expectation 😅 ok i gonna try to catch but shouldn't VS break execution when an exception is thrown?
yep that did it! thanks a lot @cap5lut
in some situations it doesnt, for example if u do not await a task where its thrown in
this is the way to $close the thread:
Use the /close command to mark a forum thread as answered
yeah but i did await the task
ig im missing something...good excuse to research some more about C# heh
well, dunno. maybe the code u where u await is already in an unawaited task
this for example doesnt make VS pause execution
using
await Task.Run(...);
instead makes it pauseumm yeah that could be it. i called the task while i was doing some other operations
thanks a lot cap! you've been extremely helpful 😊
glad i could help o7
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.