views:

90

answers:

0

hi all,

I have met a problem with asp.net. Textbox can't be updated. "Main Thread" runs on Page_load. It calls child thread, which change the text of textbox, recursively.

Here is my code

 serverSocket = new Socket(AddressFamily.InterNetwork,
        SocketType.Dgram, ProtocolType.Udp);

    //Assign the any IP of the machine and listen on port number 1000
    IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 1002);

    //Bind this address to the server
    serverSocket.Bind(ipEndPoint);

    IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
    //The epSender identifies the incoming clients
    EndPoint epSender = (EndPoint)ipeSender;

    //Start receiving data
    serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length,
        SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);  

ONRECEIVE IS CALLED. THIS STARTS WITH CHILD THREAD.
}

private void OnReceive(IAsyncResult ar)
    {

        //SOME CODE HERE....

                  txtLog.Text += msgToSend.strMessage + "\r\n";

         //UPDATE TEXT OF TEXT BOX       


                //Start listening to the message send by the user
                serverSocket.BeginReceiveFrom (byteData, 0, byteData.Length, SocketFlags.None, ref epSender, 
                    new AsyncCallback(OnReceive), epSender);
          // ONCE AGAIN CALL ONRECEIVE & GO ON

    }

Thanks all.