473,714 Members | 4,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Async Question

I am working on a project where I will have a ton of async DNS calls in a
console application. I would like to process the results of the Aync calls
on the same thread that made the async call. Now I was looking at the Async
WaitHandle options. They are "WaitOne", "WaitAny", and "WaitAll".

I would like to process all of the results that are returned. However, due
to network performance and other factors not all of the results are going to
come in at the same time. There can be up to a 2 second delay between the
start and finish of one of the async queries. However, some may return
immediately.

Of those Async options for the waithandle it does not appear that what I
want to do is possible. Did I miss something when reading the doc's on
this?

Thanks
Amy.
Nov 16 '05 #1
6 1932
Have a look at the callback part of the delegate begininvoke,
then also have a look at the Control.Inovke for getting back onto your
Control thread

"Amy L." wrote:
I am working on a project where I will have a ton of async DNS calls in a
console application. I would like to process the results of the Aync calls
on the same thread that made the async call. Now I was looking at the Async
WaitHandle options. They are "WaitOne", "WaitAny", and "WaitAll".

I would like to process all of the results that are returned. However, due
to network performance and other factors not all of the results are going to
come in at the same time. There can be up to a 2 second delay between the
start and finish of one of the async queries. However, some may return
immediately.

Of those Async options for the waithandle it does not appear that what I
want to do is possible. Did I miss something when reading the doc's on
this?

Thanks
Amy.

Nov 16 '05 #2
Brian,

That makes sense to me with a WinForms application. However, in a console
application is this still applicable and a valid approach?

Amy

"Brian Keating" <csharp at briankeating.ne t> wrote in message
news:6A******** *************** ***********@mic rosoft.com...
Have a look at the callback part of the delegate begininvoke,
then also have a look at the Control.Inovke for getting back onto your
Control thread

"Amy L." wrote:
I am working on a project where I will have a ton of async DNS calls in a console application. I would like to process the results of the Aync calls on the same thread that made the async call. Now I was looking at the Async WaitHandle options. They are "WaitOne", "WaitAny", and "WaitAll".

I would like to process all of the results that are returned. However, due to network performance and other factors not all of the results are going to come in at the same time. There can be up to a 2 second delay between the start and finish of one of the async queries. However, some may return
immediately.

Of those Async options for the waithandle it does not appear that what I
want to do is possible. Did I miss something when reading the doc's on
this?

Thanks
Amy.

Nov 16 '05 #3
Make synchronous calls on pooled worker threads if this is what you wan't.

Willy.
"Amy L." <am**@paxemail. com> wrote in message
news:u8******** ******@TK2MSFTN GP09.phx.gbl...
I am working on a project where I will have a ton of async DNS calls in a
console application. I would like to process the results of the Aync
calls
on the same thread that made the async call. Now I was looking at the
Async
WaitHandle options. They are "WaitOne", "WaitAny", and "WaitAll".

I would like to process all of the results that are returned. However,
due
to network performance and other factors not all of the results are going
to
come in at the same time. There can be up to a 2 second delay between the
start and finish of one of the async queries. However, some may return
immediately.

Of those Async options for the waithandle it does not appear that what I
want to do is possible. Did I miss something when reading the doc's on
this?

Thanks
Amy.

Nov 16 '05 #4
Willy,

If I process the calls on worker threads that will not allow me to process
the return on the thread that initiated the worker thread. Are you
suggesting this way because there is no way to implement what I suggest
Asynchronously?

Amy

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:%2******** **********@TK2M SFTNGP15.phx.gb l...
Make synchronous calls on pooled worker threads if this is what you wan't.

Willy.
"Amy L." <am**@paxemail. com> wrote in message
news:u8******** ******@TK2MSFTN GP09.phx.gbl...
I am working on a project where I will have a ton of async DNS calls in a
console application. I would like to process the results of the Aync
calls
on the same thread that made the async call. Now I was looking at the
Async
WaitHandle options. They are "WaitOne", "WaitAny", and "WaitAll".

I would like to process all of the results that are returned. However,
due
to network performance and other factors not all of the results are going to
come in at the same time. There can be up to a 2 second delay between the start and finish of one of the async queries. However, some may return
immediately.

Of those Async options for the waithandle it does not appear that what I
want to do is possible. Did I miss something when reading the doc's on
this?

Thanks
Amy.


Nov 16 '05 #5

"Amy L." <am**@paxemail. com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Willy,

If I process the calls on worker threads that will not allow me to process
the return on the thread that initiated the worker thread. Are you
suggesting this way because there is no way to implement what I suggest
Asynchronously?

Amy


What I meant was, don't use an asynchrononous pattern:
Create a worker thread to invoke a synchronous call and handle the return on
it, that way you handle both - the call and the return - on the same thread,
which was your basic requirement, right?
I don't say it's impossible to implement this using an asynchronous pattern,
if your calling thread is a UI thread, you can use Invoke/BeginInvoke to
marshal the return handler to the UI thread.
However, I don't see why you need to affinitize a return handler to a
specific thread, or am I missing something.

Willy.

Nov 16 '05 #6
clu
Yours seems quite a strange scenario for using async calls.
Async calls, by definition, do not block the caller (the calling
thread), so their result (return value, out parameters, exceptions ...)
will be received afterwards.
In .NET you can provide a callback which is invoked upon the completion
of a call, but this internally involves threads from the AppDomain
thread pool: when the result is available, one thread is picked up from
the pool (if available) and the callback is invoked into that thread's
context.
So, if you need you calling thread to process itself the results, i
believe you have two choices:
1) Make the call synchronous, which, if I'm not wrong, is not what you
want.
2) Make your calling thread pump on a work item queue. You define a
queue where work items are enqueed as soon as they are available and
implement a sort of message pump on your main thread:

// Main thread:
WorkItem item = null;
while ((item = queue.PickUpIte m() as WorkItem) != null) {

// ...

// A work item is available.
item.Process();

// ...
}

In this scenario, the async call itself may be a work item, as well as
the call's results.

The process method, for an outgoing call, should just perform the async
call, passing a callback for receiving the results.

The callback will be invoked on another thread, which should enqueue a
"result" work item to your main thread's queue.
Your main thread will keep pumping and will eventually pick up the
results and process them

I do not know if such a pattern is suitable for your application
(mainly I don't know what your main thread does !), so take it as it
is, i.e. just another idea :-)

HTH

Claudio Brotto

Nov 16 '05 #7

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

Similar topics

6
10451
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing anything. I have searched through the Internet and seems like the reason it hangs the browser it's because XMLHTTP limits you to two concurrent HTTP connections to each remote host; so if more than 2 concurrent connections strike the script...
10
2954
by: Shawn Meyer | last post by:
Hello - I am trying to write a class that has an async BeginX and EndX, plus the regular X syncronous method. Delegates seemed like the way to go, however, I still am having problems getting exactly what I want. Here are my goals 1. I would like the IAsyncResult that is returned by the Begin function to be able to be waited on or polled to check for completion. 2. The Begin function would take a callback, and the async process would
2
1537
by: Leneise44 | last post by:
Does the new async features within asp.net 2.0 and ado.net 2.0 render the async application block (1.1) extinct? What would be the advantages of using the async application block with 2.0? Seems like a lot less code can be written using 2.0 that threads safely and quickly.
6
3816
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to cause these to block? 2) You can connect together a binaryreader to a networkstream:
10
4502
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under consideration here is that it is supplied to the AsyncOperationManager.CreateOperation(userSuppliedState) method... with userSuppliedState being, more or less, a taskId. In this case, the userSuppliedState {really taskId} is of the object type,...
0
8808
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8712
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9316
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9179
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9023
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7954
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6638
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
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 we have to send another system

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.