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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Mar 19, 2012, 8:41 PM
Jignesh TrivediPosted Mar 19, 2012, 4:55 AM
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.
SenthilkumarPosted Mar 19, 2012, 12:21 AM
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