Sequence with async functions

  • Thread starter Thread starter Anders Eriksson
  • Start date Start date
A

Anders Eriksson

Most of my programs is running a sequence, e.g. a list of files, where
in the computing of the file I need to call an async function that will
return directly and the real result is returned using an event handler.

So how do I "wait" the sequence for the event to happen and then
continue with the next item in the sequence?

It feels like this is something that must have been "invented" long ago...

// Anders
 
Most of my programs is running a sequence, e.g. a list of files, where in the
computing of the file I need to call an async function that will return directly
and the real result is returned using an event handler.

So how do I "wait" the sequence for the event to happen and then continue with
the next item in the sequence?

It feels like this is something that must have been "invented" long ago...

One way would be to have your file processing loop block on a WaitHandle which
the asynchronous event handler sets just before it exits.
 
There are as many ways to do things asynchronously in .Net as there
are to skin a cat:

- 'Asynchronous Design Pattern' (http://msdn.microsoft.com/en-us/
library/aa719595(v=vs.71).aspx) - a lot of the .Net framework uses
this
- Creating threads/background worker threads/using the threadpool with
various synchronization primitives such as wait handles
(ManualResetEvent, Mutex, Semaphore, ReaderWriterLockSlim, Monitor)
- and the newest way is to use the Task Parallel libraries (http://
msdn.microsoft.com/en-us/library/dd460717.aspx)

It does seem a little odd to do each item asynchronously and wait
between each item. Is a synchronous design possible?

Regards,

Kris Sheglova
 
There are as many ways to do things asynchronously in .Net as there
are to skin a cat:

It does seem a little odd to do each item asynchronously and wait
between each item. Is a synchronous design possible?

Thanks for the tips!

The async functions are in an ActiveX control (that interfaces some
hardware) and there is only async functions...

But I was thinking maybe I can create an synchronous function that call
the async function and wait until it's done. That would make the
sequence loop very easy!

I will investigate...

Thank you to all that has had input on this matter!

// Anders
 
Back
Top