Temporizador C #. Iniciar, detener y obtener la cantidad de tiempo entre las llamadas [duplicar]
Posible duplicado:
¿Cómo medir cuánto tiempo está funcionando una función?
Estoy escribiendo un chat UDP con transferencia de datos confiable. Necesito iniciar un temporizador cuando se envía un paquete, y detenerlo tan pronto como reciba una respuesta del servidor (ACK - acuse de recibo).
Aquí está mi código:
private void sendButton_Click(object sender, EventArgs e)
{
Packet snd = new Packet(ack, textBox1.Text.Trim());
textBox1.Text = string.Empty;
Smsg = snd.GetDataStream();//convert message into array of bytes to send.
while (true)
{
try
{ // Here I need to Start a timer!
clientSock.SendTo(Smsg, servEP);
clientSock.ReceiveFrom(Rmsg, ref servEP);
//Here I need to stop a timer and get elapsed amount of time.
Packet rcv = new Packet(Rmsg);
if (Rmsg != null && rcv.ACK01 != ack)
continue;
if (Rmsg != null && rcv.ACK01 == ack)
{
this.displayMessageDelegate("ack is received :"+ack);
ChangeAck(ack);
break;
}
Gracias.