Re: Only one usage of each socket address (protocol/network address/po
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 17:46:17 -0800
On Thu, 31 Jan 2008 06:12:10 -0800, pbd22 <dushkin@xxxxxxxxx> wrote:
OK, thanks.
I sort of figured that but am unclear where exactly to post the stop
command.
If I do something like the below, the intllisense tells me that
listener.stop() will
never be reachable. Where, exactly, do i call stop??
Where you call it now would be fine, if you had any way to exit the loop. So, one fix is to change the loop so there's a way to exit it. :)
Personally, I wouldn't bother with the loop. I'd use the asynchronous API so that I didn't have a thread sitting blocked at a call to an Accept method, and thus I could stop and close the socket wherever I like without worrying about some thread that I needed to coordinate with.
But barring that, another alternative would be to put a try/catch around the call to AcceptTcpClient() and then just stop the listening socket from somewhere else when you need to shut down the service. Then you catch the exception that's thrown when the socket is stopped and closed, and in that way detect that it's time to exit the loop (of course, in that scenario there's no need to call Stop() after the loop, since calling Stop() and Close() would be what got you out of the loop in the first place :) ).
Pete
.
- Follow-Ups:
- Prev by Date: Re: c# File Compare / Merge
- Next by Date: Re: re-line up source
- Previous by thread: Re: c# File Compare / Merge
- Next by thread: Re: Only one usage of each socket address (protocol/network address/po
- Index(es):
Relevant Pages
|