Hi, I have this simple sample code:
class SearchRange
{
static int m = 0;
static void Main(string[] args)
{
Discover discover = new Discover();
// Add discovered device handler
discover.DiscoverUpdate += DiscoveredDeviceCallback;
// Add progress handler
discover.ProgressUpdate += ProgressCallback;
Console.WriteLine("Discovered devices:");
// Start searching for devices
IAsyncResult ar = discover.BeginSearchRange("193.93.73.180",
"193.93.73.190",
1000, CompletedCallback, null);
discover.EndSearchRange(ar);
Result result;
DiscoveredDevice discoveredDevice = discover.EndSearchAddress(ar,
out result);
Console.WriteLine("\nResult: {0}", result.Status);
if (discoveredDevice != null)
Console.WriteLine("Discovered device: {0}\n",
discoveredDevice.Name);
}
private static void DiscoveredDeviceCallback(object sender,
DiscoverEventArgs e)
{
DiscoveredDevice device = e.DiscoveredDevice;
Console.WriteLine("{0} {1} {2}", device.SerialNumber,
device.IPAddress, device.Name);
}
private static void ProgressCallback(object sender, ProgressEventArgs
e)
{
Console.WriteLine("Progress: {0}%", e.Progress);
Thread.Sleep(300);
}
private static void CompletedCallback(IAsyncResult ar)
{
Console.WriteLine("Completed Callback!\n");
}
}
class Discover is implemented as asynchronous design pattern
(asynchronous methods are BeginSearchAddress, EndSearchAddress).
ProgressCallback is callback for event ProgressUpdate. That code has
the correct progress output (e.g. 20% 30% ... 100%) if
Thread.Sleep(300) is commented else program get bad progress output
(e.g. 20% 30% ... 100% 60%). I know that CompletedCallback is called
when the request (BeginSearchAddress) is completed, and the EndRequest
call will wait until the request is complete and return the result.
Those are know things. And what event? Does the event [event callback]
need in the class implemented as asynchronous design pattern special
handling of the itself code? Where can I found information about this
problem? Thanks and best regards
Marian.