Click to See Complete Forum and Search --> : Failed Socket.Send causes device to slow down


Allan Olesen
February 3rd, 2008, 09:55 AM
I have problems with a program for SmartPhone 2003 using .NET CF 1.0. I don't know if this is a C# problem or a SmartPhone problem.

Every 30 seconds the program sends a short UDP packet via GPRS, using the code below. If the packet is sent succesfully, SendPacket returns true. If the phone has no usable data connection, SendPacket will immediately return false (which is good), but unfortunately the phone menus (all menus, not just in this program) get very unresponsive after only a few failed attempts. There is no increased memory usage so I am assuming heavy CPU load.

I am wondering if I need to do some manual cleanup after a failed attempt. I have until now assumed that the packet will just "disappear" when the .Send method throws an exception, but now I think that something is left behind.

This is the socket:private Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

socket.Connect(new IPEndPoint(IPAddress.Parse(RemoteAddress), RemotePort));


This is the code for sending a packet:
public bool SendPacket(byte[] sendData)
{
try
{

socket.Send(sendData);
return true;
}
catch (Exception)
{
return false;
}
}