(Copied to DOTNET-CLR and DOTNET - please direct replies to DOTNET-CLR - the
DOTNET list will be shut down soon.  Please refrain from starting new
threads on the DOTNET list.)

If we're talking about using BeginInvoke on a delegate, then it's just one
of the many ways of getting code to run on another thread.  So since it *is*
executing code on another thread, strictly speaking there is no difference
between it and executing a method in another thread...

There are differences between this way of executing a method in another
thread an the various other ways.  For example, you can use a Timer to do
this - the difference being that timers can be used to launch the method on
another thread at some specified point in the future and possibly repeatedly
at regular intervals.  Async invocation through a delegate executes the
method as soon as possible.

The differences between async delegate invocation and, say, creating your
own thread and running the method there are (a) delegates are typically
easier to use, (b) async delegates will use the system thread pool, which
may have better scalability behaviour than creating your own threads (c)
async delegates propagate more of the security context of the original
thread.

The differences between async invocation with a delegate, and async
invocation with the ThreadPool class are less obvious.  There is a subtle
difference in propagation of security context.  Also, delegates are slightly
easier to use.


If however you're talking about async method calls on the Socket class,
that's different again.  That performs operations asynchronously, this is
not the same as invoking the method on another thread.  (It is more akin to
classic async file IO in Win32, or nonblocking use of BSD sockets, neither
of which had to involve more than one thread.)


--
Ian Griffiths
DevelopMentor


----- Original Message -----
From: "franklin gray" <[EMAIL PROTECTED]>


With the discussions of late about Asynchronous calls, I have to ask.  What
is the difference between it and executing a method in another thread?

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to