Essentially, what are the differences between these beyond the obvious? When should I use which form?
class What
{
public Go()
{
Thread thread = new Thread(new ThreadStart(Go2));
thread.Background = true;
thread.Start();
}
private Go2()
{
using UdpClient client = new UdpClient(blabla)
{
while (stuff)
{
client.Receive(guh);
DoStuff(guh);
}
}
}
}
versus
class Whut
{
UdpClient client;
public Go()
{
client = new UdpClient(blabla);
client.BeginReceive(guh, new AsyncCallback(Go2), null);
}
private Go2(IAsyncResult ar)
{
client.EndReceive(guh, ar);
DoStuff(guh);
if (stuff) client.BeginReceive(guh, new AsyncCallback(Go2), null);
else client.Close();
}
}