I am relatively new to socket programming and I have not been able to solve
the following issue. Can some please help.
I have created an async socket listener and I have followed pretty much the
Asynchronous Socket Examples in the MSDN Library, with the exception that I
am writing a Windows Service. It works fine, but when I try to stop it
through the services window it times out and does not stop the service. I can
see the exe in the Task Manager.
In my OnStop method I have the following:
If m_Listener.Connected = True Then
m_Listener.Shutdown(SocketShutdown.Both)
End If
m_Listener.Close()
Now I have run my service in debug mode without making a client connection
to it before stopping it as a simple test and run into the same problem. I
have a theory on what happening, but I'm not sure and need some help.
I think that after executing the following
'Nonsignal state must complete activity before threads proceed
m_ManualResetEvent.Reset()
'Begins to accept client connection asynchrounously
m_Listener.BeginAccept(New AsyncCallback(AddressOf AcceptCallBack),m_Listener)
'Thread waits untils it recieves a signal by Set method
m_ManualResetEvent.WaitOne()
It is waiting for the a connection of a client through the AcceptCallBack
which will do:
'Signals the main thread to proceed
m_ManualResetEvent.Set()
and the EndAccept method. My theory is that it hangs because the EndAccept
has not been called.
Can anyone help me or point me in the right direction please!