asynchronous programming in .net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know a good tutorial on asynchronous programming in .net

AsyncCallback And IASyncResult are driving me crazy. And the msdn documentation is not really helpful on this topic

I appreciate any recommendation.
 
Hi Anonymous

Have a look for "remoting" on msdn, I think the first week you have enough
to do reading about async.

You can also download the vb. resource kit there are samples in it.

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir
I hope this helps a little bit?

Cor

Does anyone know a good tutorial on asynchronous programming in .net?

AsyncCallback And IASyncResult are driving me crazy. And the msdn
documentation is not really helpful on this topic.
 
If you want VB try Visual Basic .NET Power Coding, for C3
try Advanced C#, or sign up for the VB Today codeguru.com
newsletter. The VB Today columns should have a couple
examples.

The callback is a delegate/function pointer that does the
work, and the IAsyncResult is a waithandle (I think!?) for
blocking.

Paul
-----Original Message-----
Does anyone know a good tutorial on asynchronous programming in .net?

AsyncCallback And IASyncResult are driving me crazy. And
the msdn documentation is not really helpful on this topic.
 
As Cor mentioned, you could use some of the samples in the Remoting
infrastructure, although multithreading and asynchronous programming don't
have to involve remoting - remoting is more or less the .net version of
DCOM.

Here's some links that may help you out with threads and asynchronous
programming.

http://msdn.microsoft.com/library/d...n-us/vbcn7/html/vaconFreeThreadingExample.asp

http://msdn.microsoft.com/msdnmag/issues/01/07/vbnet/default.aspx

http://msdn.microsoft.com/library/d...dowsformsmultithreadedtciiplistenersample.asp

I suggest you also look up topics relating to the "thread pool" and
asynchronous delegates.

Here's a quick example on how to call a method asynchronously in VB.net with
one parameter (there are more ways to do this, but this is just a simple
example)

-------------------------

' Delegate to call async
Private Delegate Sub DoStuffDelegate(Byval MyParam as String)



' Main Entry point
Private Sub Main()

' Local Variables
Dim DoStuffAsync as new DoStuffDelegate(AddressOf Me.DoStuff)
Dim objResult as IAsyncResult

' Start the async processing
objResult = DoStuffAsync.BeginInvoke(nothing, nothing)

' Do some stuff in this thread
Threading.Thread.Sleep(5000)

' Pause until the processing has finished
DoStuffAsync.EndInvoke(objResult)

End Sub


' Method that runs on a different thread
Private Sub DoStuff()

' Do stuff on a different thread
Threading.Thread.Sleep(10000)

End Sub

-------------------------

HTH,

Trev.


... said:
Does anyone know a good tutorial on asynchronous programming in .net?

AsyncCallback And IASyncResult are driving me crazy. And the msdn
documentation is not really helpful on this topic.
 
Ok, but, doesnt a normal delegate doesnt do the work in the same manner as a AsyncCallback delegate? What is the difference? Its not like the asynchronous delegate works indeed asynchronous to the parent program

----- Paul Kimmel wrote: ----
The callback is a delegate/function pointer that does the
work, and the IAsyncResult is a waithandle (I think!?) for
blocking

Pau
 
Sorry. Bug Fix.... (forgot the parameter!)

-------------------------

' Delegate to call async
Private Delegate Sub DoStuffDelegate(Byval MyParam as String)



' Main Entry point
Private Sub Main()

' Local Variables
Dim DoStuffAsync as new DoStuffDelegate(AddressOf Me.DoStuff)
Dim objResult as IAsyncResult

' Start the async processing
objResult = DoStuffAsync.BeginInvoke("test", nothing, nothing)

' Do some stuff in this thread
Threading.Thread.Sleep(5000)

' Pause until the processing has finished
DoStuffAsync.EndInvoke(objResult)

End Sub


' Method that runs on a different thread
Private Sub DoStuff(Byval Param as String)

' Do stuff on a different thread
Threading.Thread.Sleep(10000)

End Sub
 
To be honest.. not really. My problem is, i dont see the advantage of
the AsyncCallback delegate over a normal delegate.. What is the
advantage? The only advantage that i can see, is the IAsyncResult
object, that has useful members.

Maybe i dont got it, can someone explain it to me? Asynchronous over
synchronous.

Just because a delegate is a delegate doesn't mean that it runs
asynchronously. Normal delegates have to complete their processing before
the call to invoke the delegate will return.

-mdb
 
Back
Top