ertaboy356b
Old School Gamer
- Reaction score
- 86
Ok, so I was working on a program in C#. During the beta testing (which is composed of at least 80 participants), loads of problems arise. One problem is that sometimes the socket server was not able to send back the data to the client and because of this, I developed this function for sending out serialized network objects via sockets.
This code makes the socket sending mechanism persistent up to 10 times. Is it okay to use 'goto' or is their another way to code this function?
Code:
private static void SendObject(UserData u,string packetType, object message)
{
var failCount = 0;
RESEND:
try
{
// Send Object to the User
u.Connection.SendObject(packetType, message);
}
catch (Exception ex)
{
failCount++;
Console.WriteLine(ex.Message + " Resending....");
if (failCount < 10) {
goto RESEND;
}
}
}
This code makes the socket sending mechanism persistent up to 10 times. Is it okay to use 'goto' or is their another way to code this function?