Thursday, April 12, 2007

Calling Delegates Asynchronously

using System;
using System.Threading;

public class Test
{
delegate int TestDelegate(string parameter);
static void Main()
{
TestDelegate d = new TestDelegate(PrintOut);
d.BeginInvoke("Hello", new AsyncCallback(Callback), d);
// Give the callback time to execute - otherwise the app
// may terminate before it is called
Thread.Sleep(1000);
}
static int PrintOut (string parameter)
{
Console.WriteLine(parameter);
return 5;
}
static void Callback (IAsyncResult ar)
{
TestDelegate d = (TestDelegate)ar.AsyncState;
Console.WriteLine ("Delegate returned {0}", d.EndInvoke(ar));
}
}

Thursday, April 5, 2007

Tracing network Root using .NET code

To trace the route from your location to a distant IP address, you perform multiple ping attempts.

On the first attempt, the TTL parameter is set to 1, causing the first network node to cease forwarding and return an error.

The error contains information about that node.

On the next attempt, the TTL parameter is set to 2, causing the second node in the path to return an error.

The TTL parameter is incremented by 1, causing each subsequent node to return an error until the destination is reached.

This provides information about every node on the path between your machine and the destination server.

 

For complete .NET code check http://msd2d.com/newsletter_tip.aspx?section=dotnet&id=abf47aa9-ec5b-456e-a2f9-1ad0fd10a2f5

 

Labels