0

I have a problem where my application crashes what seems to be at random. It works for maybe up to 30 min, and then I just crashes, if I debug I get an error at the row mySocket.SendAsync(completeArgs) It's a stackoverflow error... I do the following lines of code everytime I want to send something, and that is quite alot, maybe something every 0.5 second. I have tryed to set mySocket.NoDelay = true; but that did not solve the problem. This is the client side of the applications.

SocketAsyncEventArgs completeArgs = new SocketAsyncEventArgs();
completeArgs.SetBuffer(MsgBuffert, 0, MsgBuffert.Length);
completeArgs.UserToken = this.mySocket;
completeArgs.RemoteEndPoint = this.hostEndPoint;
completeArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnSend);

mySocket.SendAsync(completeArgs);
Nick3
  • 639
  • 1
  • 14
  • 40
  • 2
    Your error is probably somewhere else; the `SendAsync` call is just what pushes the stack over the edge. Consider looking for instances of unbounded recursion in your code. – nneonneo Sep 13 '12 at 11:19
  • Rather than blindly sending every 0.5s, shouldn't you be checking that in the `OnSend` handler? AFAIK, the API does not support concurrent calls to `SendAsync` on the same socket. Also: are you handling the return value of `SendAsync`? (you are meant to; I was *actually* expecting to see `if(!mySocket.SendAsync(completeArgs)) OnSend(this, completeArgs);`, in which case I suspect I know what would be wrong, but: you are meant to handle the return val... also: part of the *point* of `SendAsync` (i.e. why it exists) is so you don't need a new `SocketAsyncEventArgs` for every operation... – Marc Gravell Sep 13 '12 at 11:28
  • 2
    For a stack overflow, though, probably the most important thing is: how does the "do the next thing" code work? do you call it at the end of your send code? stack overflow is almost always about *call depth*, i.e. A calling B which calls A which calls B which calls A which calls B etc. I suspect the sending details are completely unrelated. – Marc Gravell Sep 13 '12 at 11:34
  • I think you guys are right, havent tryed yet, but I called the send function from the sendfunction.... not to smart when you think about it :P – Nick3 Sep 13 '12 at 11:45

0 Answers0