3
본질적으로, 명백한 것 이상의 차이점은 무엇입니까? 어떤 양식을 사용해야합니까?언제 UdpClient.BeginReceive를 사용해야합니까? 백그라운드 스레드에서 UdpClient.Receive를 사용해야하는시기는 언제입니까?
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);
}
}
}
}
내가 차이는 일반적으로 거대 할 것이라고 생각하지 않지만, 나는 전체 비동기 방식을 선호하는 나는 일시 정지를 기대한다면 (.../끝 ... 시작) 할
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();
}
}