asynccallback vs event

  • Thread starter Thread starter Chris Small
  • Start date Start date
C

Chris Small

Can anyone explain the difference between the two? Which is more reliable
for large jobs?
 
Chris,

They are both the same really. I mean, an event can serve as an
asychronous callback if you wish. There are three ways to handle
notifications for anything, either through reflection, an interface, or a
delegate. The easiest way is through a delegate, the next easiest being an
interface, and finally reflection.

Delegates are a fine way to handle asynchronous callbacks. What are you
trying to do?

Hope this helps.
 
Chris said:
Can anyone explain the difference between the two? Which is more
reliable for large jobs?

There is one important difference between the two. The Async call is made on
a thread pool thread, hence the callback method is called on a thread pool
thread. The event delegate is called on the thread that raised the event.
You can specify the COM apartment type that will be used for the thread that
raises the event. You don't know which thread pool thread will be used to
handle an Async call, and by default if you use a COM object on a thread
pool thread the thread will join the MTA. I've seen code that has failed
because a MTA is used instead of an STA and this was solved by changing the
code so that it did not make an Async call.

Richard
 
Back
Top