I managed to ensure that they do not need to intercept the error and my service stops after finally perfectly Changes 2 3.
Here's how I did it to avoid the intercept:
I used just a boolean that as soon as I invoke my method OnStop of the service, it will call a method in my class my listener passing a boolean false, therefore if a little before listening to an incoming connection:
Code:
public static void DoAcceptTcpClientCallback (IAsyncResult ar)
(
if (run)
(
Tracer. Trace ( "Connection detected");
/ / Blocking call to accept requests
using (TcpClient client = ((TcpListener) ar. AsyncState). EndAcceptTcpClient (ar))
......
)
else
(
tcpClientConnected. Set ();
)
(
To stop doing your service as:
Code:
HTTPServer. Arret () / / method that passes a boolean false;
Dispose ();
Tracer. Trace ( "Canstop");
CanStop = true;
method stop:
Code:
public static void Stop ()
(
run = false;
tcpClientConnected. Set ();
listener. Stop ();
)
Tell me if you're successful!
Bookmarks