Socket.SendAsynch (Tcp) method sometime throw AccessViolationException RRS feed

  • Question

  • Hi, I posted this in .NET class library forum but I got no answers yet after a couple of days so I hope I will have more success here!

    Here is a copy of the post:

    Hi, I have a program that use the Socket.SendAsynch method to send data thru a tcp connection. Sometimes I get an AccessViolationException. I have no clue why this is hapenning and I think it cause the program to close without any error messages when running outside the debugger (I have a friend running my program and he is telling me that it crash regulary at approximately 4hours intervals, without any error message) and I suspect the AccessViolation is causing it.

    On my dev comp it happens once in awhile but on my test comp I never get that error (well I might get it eventually but I tested it running for 40+ hours and I did not had a single crash).

    When looking at MSDN documentation, I see that the SendAsynch method is not supposed to throw an access violation.

    I tryied to create a copy of the buffer because I was thinking that maby it was getting locked somewhere, but it dosent work either. This is my send code:

    SocketAsyncEventArgs send = new SocketAsyncEventArgs(); 
    byte[] sendBuffer = (byte[])data.Clone(); 
    send.SetBuffer(sendBuffer, 0, sendBuffer.Length); 
    send.Completed += new EventHandler<SocketAsyncEventArgs>( 
                    delegate(object sender, SocketAsyncEventArgs e) 
                        if (PacketSent != null
                            PacketSent(origin, data, e.BytesTransferred); 
                        this.PacketHandler.AddPacket(origin, data); 

    Tuesday, July 15, 2008 11:56 PM