Does AsyncCallback start a new thread?
Posted on 2004-10-20
I need help with a problem i am having...
I have made a simple program that starts and create a thread that makes a connection to a server.
What i want to do is have my mainthread doing some gui-stuff, and a socket-thread that handles all the socket-stuff.
So i made a class that have a function called Start that makes a connection, and then sets a asynccallback:
m_sock.Blocking = false;
AsyncCallback onconnect = new AsyncCallback( OnConnect );
m_sock.BeginConnect( epServer, onconnect, m_sock );
then when it runs OnConnect:
AsyncCallback Receivedata = new AsyncCallback( OnReceivedData );
sock.BeginReceive( m_byBuff, 0, m_byBuff.Length, SocketFlags.None, Receivedata, sock );
What i was thinking is that the socket thread that starts with this funtion should only handle the socket stuff.
But when i run my program and the socket is set up my socket-thread dies beacuse the function has ended.
But the funny thing is that i can still receive data on my socket?
When i make these AsyncCallbacks and they gets triggered, do they start their own thread?
So my question is this, since my program is running and can handle incoming data eventhough my thread that started the socket has died...which thread is handling my OnReceivedData???
Any help and/or remarks will be much appreciated!
Thanks for you help!