Hi friends,
I want to know that which method would be used to invoke a delegate type asynchronously in c#? Give an example with code?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Mar 18, 2012, 8:21 PM EDT
The BeginInvoke and EndIvoke methods are used.
You can find example in the following urls:
http://stuarthallows.wordpress.com/2011/03/07/calling-a-delegate-asynchronously-various-methods/
http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx
http://msdn.microsoft.com/en-us/magazine/cc301332.aspx
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 19, 2012, 12:55 AM EDT
Delegates are special types supported by the .NET Framework that represent a strongly typed method signature.
Delegates can be instantiated and formed over any target method and instance combination where the method matches the method's signature.
C# allows us to create special classes using the delegate keyword.
Delegate has two methods named BeginInvoke and EndInvoke. The signatures of these methods are based on the signature of the delegate type.
delegate int Add(int x, int y)
exposes by compiler generation
IAsyncResult BeginInvoke(int x, int y, AsyncCallback callback,
object object, IAsyncResult result);
int EndInvoke (IAsyncResult result);
Add d = ShowSum;
IAsyncResult ar = d.BeginInvoke(10, 10, null, null);
int sum = d.EndInvoke(ar);
public int ShowSum( int x, int y ) {
return x + y;
}
please refer
http://www.codeproject.com/Articles/14931/Asynchronous-Method-Invocation
hope this help.
Sam HobbsRank #107 · 20.5K reputationPosted Mar 19, 2012, 4:41 PM EDT