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 4 4176
I always liked the bedtime story... http://www.sellsbrothers.com/writing...=delegates.htm
"theBoringCoder" <tb*****@isd.sbcounty.gov> wrote in message
news:ad****************************@phx.gbl... 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
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/de...sdelegates.asp
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"theBoringCoder" <tb*****@isd.sbcounty.gov> wrote in message
news:ad****************************@phx.gbl... 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
Yeah, that is a funny story. -----Original Message----- I always liked the bedtime story...
http://www.sellsbrothers.com/writing/default.aspx?
content=delegates.htm "theBoringCoder" <tb*****@isd.sbcounty.gov> wrote in
messagenews:ad****************************@phx.gbl... 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
.
Thanks. That helps a lot. -----Original Message----- 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 ofthe 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 ofthe .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] - mv*@spam.guard.caspershouse.com
"theBoringCoder" <tb*****@isd.sbcounty.gov> wrote in
messagenews:ad****************************@phx.gbl... 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
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen |
last post by:
I am new to C# and can't get my head round what delegates
are and what they are for. can anyone enlighten me?
|
by: Brian Corcoran |
last post by:
I am writing an application whose job is to run other programs. A scheduler
of sorts.
Each of the tasks it runs are like plug-ins, they are in other assemblys
and created when needed.
After...
|
by: Max |
last post by:
Is there a built in way to run a piece of code asynchronously? I'd like to
run some code in the background that's triggered by a user action on a web
page.
Examples of what I'm talking about:...
|
by: Mike |
last post by:
I want a class to fire a method in another class, and once it fires
it, to not care about what happens (i.e., if there are errors, return
values, etc). I want this to happen asynchronously.
I...
|
by: Turbo |
last post by:
I need to be able to update the content on the client machine when a web
service event is fired or an asynchronous callback routine is executed. For
example, I open a page that will display a...
|
by: djc |
last post by:
here is my task:
I am writing a command line utility that I can use to quickly reboot some
wireless access points (why? short answer: budget). That part is already
done. All it does is send the...
|
by: r1 |
last post by:
I am relatively inexperienced in using delegates and asynchronous
methods. I read several articles, and then I developed my own code
with a mission to improve the performance. Wow! I cannot...
|
by: =?Utf-8?B?bWs=?= |
last post by:
Hi everyone,
I need to refactor some of our processes using the asynchronous programming
model. I have defined a couple of arrays of delegates to pipline the
asynchronous invocations through...
|
by: Frankie |
last post by:
I have just gotten up to speed on what anonymous methods are (syntax,
capabilities, etc), and how they can be used with /called via delegates.
What I am wondering is...
1. Are they only/mostly...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |