473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

asynchronous design pattern and event

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.

Jul 23 '07 #1
0 1600

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Julian Hershel | last post by:
Reading about asynchronous programming (ms-help://MS.NETFrameworkSDK/cpguidenf/html/cpconasynchronousdesignpatterno verview.htm) I could not clarify some doubts. Hope you can help me. 1) Are...
2
by: Ronodev.Sen | last post by:
the way my program needs to go is -- 1) open a socket and listen on it 2) moment a client connects to the socket - process some data (by sending it to another machine), get the result and send...
1
by: colinjack | last post by:
Hi All, I've been using the original (non-event based) asynchronous design pattern using delegates. It works fine but performance wise I know using the ThreadPool is supposed to be far better,...
3
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I need to build an event-based asynchronous pattern (around a send/receive messaging API). Is there a step-by-step guidance about how to write code for the EBAP ? Does any book cover this theme...
4
by: MaxMax | last post by:
I'm using HttpWebRequest. It seems that all the callback called from HttpWebRequest are in another thread (not in the "original" thread). Now my problem is that the "original" thread is the thread...
1
by: jan.loucka | last post by:
I'm developing WinForms application in .NET 2.0 that talks to web service. The automatically generated proxy (reference class) has got methods for both synchronous and asynchronous invocations of...
1
by: jan.loucka | last post by:
I'm developing WinForms application in .NET 2.0 that talks to web service. The automatically generated proxy (reference class) has got methods for both synchronous and asynchronous invocations of...
4
by: Morgan Cheng | last post by:
Since ASP.NET 2.0, asynchronous web service client can be implemented with event-based pattern, instead of original BeginXXX/EndXXX pattern. However, I didn't find any material about event-based...
0
by: Morgan Cheng | last post by:
Since ASP.NET 2.0, asynchronous web service client can be implemented with event-based pattern, instead of original BeginXXX/EndXXX pattern. However, I didn't find any material about event-based...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.