AsynCallback
-
Public AsynCallback pfnWorkerCallBack; //Define a global reference public void WaitForData(System.Net.Sockets.Socket soc,int clientNumber) { try { if( pfnWorkerCallBack == null ) {pfnWorkerCallBack = new AsyncCallback (OnDataReceived);} SocketPacket theSocPkt = new SocketPacket (soc, clientNumber); soc.BeginReceive (theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length,SocketFlags.None,pfnWorkerCallBack, theSocPkt); } } public void main() { WaitForData(Socket1,1); WaitForData(Socket2,2); } Question: 1.When the 1st WaitForData(Socket1,1) started, pfnWorkerCallBack is definitely equal to NULL so a new AsynCallback is created and assigned to pfnWorkerCallBack. What happen to pfnWorkerCallBack when the second WaitForData(Socket2,2) started? 2.When a same method was started asynchronously for several times. Are all method's variables refer to the same variables?