Wednesday, March 28, 2012

Simple asynchronous method call

Hello all,
Could somone please help! I'm trying to fire an asynchronous method but all
the examples I'm finding are pretty complex.
The basic thing I need to do is:
1) Do some logic
2) Fire off a method (threading needed?)
3) Without the above finishing, continue with other things.
The problem I have is that I don't want to wait for the method to finish
before I have to continue. Can this be done? It seems simple in principle.
Thanks all,
Jon> 2) Fire off a method (threading needed?)
The functionality you're looking for is supported by delegates. A
delegate contains a reference to a function (see MSDN.)
Once you have the delegate set up, you can call BeginInvoke() to start
an asynchronous call. If you don't specify a callback function, you can
just forget about it from that point and continue with other things.
Greetings,
Wessel
> Once you have the delegate set up, you can call BeginInvoke() to start
> an asynchronous call. If you don't specify a callback function, you
> can just forget about it from that point and continue with other
> things.
Actually, you do need to worry about it after you call BeginInvoke regardles
s
of wether you want a return value. IOW, you must call EndInvoke (this can
be done from a callback function, so it's not so bad). The docs state that
the runtime reserves the right to leak resources if you fail to call EndInvo
ke.
This documentation was added in v1.1, so people who wrote in v1.0 weren't
aware of this issue.
-Brock
DevelopMentor
http://staff.develop.com/ballen

0 comments:

Post a Comment