473,323 Members | 1,589 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,323 software developers and data experts.

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 1886
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.net> wrote in message
news:6A**********************************@microsof t.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**************@TK2MSFTNGP09.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******************@TK2MSFTNGP15.phx.gbl...
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**************@TK2MSFTNGP09.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****************@TK2MSFTNGP14.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.PickUpItem() 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
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...
10
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...
2
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...
6
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...
10
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.