473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About Asynchronous method invocation

Asynchronous method model generally has a callback delegate as
argument. The delegate will be called when some WaitHandle is set or
time out. And, one more argument is used as state object to transfer
any customized data into callback delegate. I believe that is un-
necessary.

For example,
public static RegisteredWaitHandle RegisterWaitForSingleObject (
WaitHandle waitObject,
WaitOrTimerCallback callBack,
Object state,
int millisecondsTimeOutInterval,
bool executeOnlyOnce
)

public delegate void WaitOrTimerCallback (
Object state,
bool timedOut
)
the parameter state is to used as first argument to delegate
WaitOrTimerCallback. We can package something into a customized
object, and cast it back to real value in delegate to extract info.

With the help of anonymous delegate, the state object can always be
ignored.

int foo = 23;
string bar = "abc";

AutoResetEvent ev = new AutoResetEvent(false);
ThreadPool.RegisterWaitForSingleObject(
ev,
delegate(object state, bool timedOut)
{
Console.WriteLine("{0}, {1}", foo, bar); //just
use it directly
}
null, //can always be null
2000,
true
);

Is there any problem in my understanding?
Thanks,

Jun 15 '07 #1
1 1933

The asynchronouse method invocation architecture predates anonymous
delegates. Also, not everyone wants to use an anonymous delegate
every time to pass state data, sometimes the state object is better
for the situation (particularly when using a generic callback delegate
that used in many places).

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 14 Jun 2007 19:43:07 -0700, Morgan Cheng
<mo************@gmail.comwrote:
>Asynchronous method model generally has a callback delegate as
argument. The delegate will be called when some WaitHandle is set or
time out. And, one more argument is used as state object to transfer
any customized data into callback delegate. I believe that is un-
necessary.
....
>
Is there any problem in my understanding?
Thanks,
Jun 15 '07 #2

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

Similar topics

0
by: Mom developer | last post by:
Is there any one that has successfully used Asynchronous Invocation Application Block. I cannot find any resources other than the help file and the article at...
2
by: Jet Leung | last post by:
Hi All, There is a problem about asynchronism process.If I run the method by BeginInvoke() and how can I know when the method is finish? And maybe I can say when I can use EndInvoke()?
6
by: Sharon | last post by:
How to catch an asynchronous delegate invocation exception? The code: --------------------------------------- String message = “my message”; foreach( MyDelegate handler in...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
9
by: Sharon | last post by:
I have a remoting object, lets call it A, that fires an event to remotely registered handlers, lets call it B. The invocation is working OK and the remote handler B is handling the event like it...
0
by: Bishoy George | last post by:
Hi, I have a asp.net 2.0 web application. I want to implement the asynchronous model through http handler in web.config ...
0
by: sloan | last post by:
http://msdn2.microsoft.com/en-us/library/ms998466.aspx Asynchronous Invocation Application Block for .NET Does anyone know why that block was "abandoned" ? Is there some kind of replacement...
1
by: Morgan Cheng | last post by:
I have one webservice that involves time-costing computation. For each request, it consumes about 2 seconds computation. Since ASP.NET has 25 threads per CPU to handle requests, this delay turns to...
8
by: wangdaixing | last post by:
I am reading "Programming .NET Components" 2nd Edition by Juval Lowy, O'Reilly. In Appendix E, there is a chapter "Coding Practices" which I agree and practice mostly. However, there are a few...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

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.