Search:
Namespaces
Discussions
.NET v1.1
Feedback
Asynchronous Methods and Delegates
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.languages.csharp
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
theBoringCoder
Hello All,
I just started learning about Delegates, and was wondering
if someone could point me at some useful, straightforward
examples of how to use delegates to make method calls
asynchronously. I've been told that this is possible, and
works similar to callbacks in C++, but cannot find any
straightforward examples in C#.
Thanks,
theBoringCoder
Reply to this message...
Andy Gaskell
I always liked the bedtime story...
http://www.sellsbrothers.com/writing/default.aspx?content=delegates.htm
"theBoringCoder" <
Click here to reveal e-mail address
> wrote in message
news:ad2001c436ca$7e22a570$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
theBoringCoder
Yeah, that is a funny story.
[Original message clipped]
Reply to this message...
Nicholas Paldino [.NET/C# MVP] (VIP)
theBoringCoder,
It's actually quite easy. If you create a delegate like this:
public delegate void MyMethodDelegate(int myParam);
Then an instance of a delegate exposes three methods, Invoke,
BeginInvoke, and EndInvoke. What you want to do is create an instance of
the delegate, and then call the BeginInvoke method, like so:
// Create the delegate.
MyMethodDelegate pobjDelegate = new MyMethodDelegate(MyMethod);
// Call asynchronously.
IAsyncResult
pobjResult = pobjDelegate.BeginInvoke(1, null, null);
For a more detailed explaination and examples, check out the section of
the .NET framework documentation titled "Asynchronous Delegates", located at
(watch for line wrap):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpovrasynchronousdelegates.asp
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
Click here to reveal e-mail address
"theBoringCoder" <
Click here to reveal e-mail address
> wrote in message
news:ad2001c436ca$7e22a570$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
theBoringCoder
Thanks. That helps a lot.
[Original message clipped]
us/cpguide/html/cpovrasynchronousdelegates.asp
[Original message clipped]
Reply to this message...
System.IAsyncResult
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com