Search:
Namespaces
Discussions
.NET v1.1
Feedback
BeginInvoke() and EndInvoke() not available in delegates for asynchronous execution of methods
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.vjsharp
.
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...
Sameeksha
Hi,
The following code does not work in J#.
IAsyncResult
ar1 = sampleDelegate.BeginInvoke(new
AsyncCallback
(AsyncResultSample.MyCallback),
new
Object
[] { (Int32)param, (Int32)param });
It gives compilation error as BeginInvoke not available for delegates. Anybody knows a way to handle asynchronous execution of methods in J#?
Reply to this message...
pratap [MSFT] (VIP)
BeginInvoke and EndInvoke take additional parameters. Ensure you are
passing the right parameters.
Here are a couple of examples:
(1) It is legal to omit the call to EndInvoke if the result of the call is
not important. In the following e.g. the delegate is invoked asynchronously
and we wait till the call completes.
/** @delegate */
public delegate void Proc();
public class myclass
{
public static void display() { System.out.println("hello world"); }
public static void main(String [] args)
{
Proc p = new Proc(myclass.display);
// invoke asynchronously
System.
IAsyncResult
ar = p.BeginInvoke(null, null);
// sleep until the call completes
ar.get_AsyncWaitHandle().WaitOne();
}
}
(2) Optinaly, you can process the result of an asynchronous invocation by
passing an asynchronous "completion routine" to the BeginInvoke method when
you issue the call. In the following e.g. the completion routine is passed
as the second-last argument to BeginInvoke. The completion routine is
responsible for calling EndInvoke to harvest the results of the method
call. To allow EndIvoke to be called at completion time a reference to the
delegate is also passed in as the last parameter to BeginInvoke.
/** @delegate */
public delegate int Proc(int i, int j);
public class myclass
{
public static int sum(int i, int j) { return i + j; }
public static void main(String [] args)
{
Proc p = new Proc(myclass.sum);
System.
AsyncCallback
cb = new
System.
AsyncCallback
(myclass.onCompletion);
// invoke asynchronously
System.
IAsyncResult
ar = p.BeginInvoke(2, 2, cb, p);
System.out.println("Invoked asynchronously");
}
public static void onCompletion(System.
IAsyncResult
ar)
{
System.out.println("Get the delegate");
Proc p = (Proc) ar.get_AsyncState();
System.out.println("Get the result");
int sum = p.EndInvoke(ar);
System.out.println("The sum: " + sum);
}
}
Hope this helps.
Thanks for your interest in Visual J# .NET.
pratap
Visual J# .NET Team
--------------------
>Thread-Topic: BeginInvoke() and EndInvoke() not available in delegates for
asynchronous execution of methods
[Original message clipped]
IAsyncResult
ar1 = sampleDelegate.BeginInvoke(new
AsyncCallback
(AsyncResultSample.MyCallback),
new
Object
[] { (Int32)param, (Int32)param });
It gives compilation error as BeginInvoke not available for delegates.
Anybody knows a way to handle asynchronous execution of methods in J#?
>
Reply to this message...
Sameeksha
Hi,
Thanks for your help. It helped me write BeginInvoke() function call. But when I try to write EndInvoke() in the way you have specified, it causes a compilation error saying that no such method EndInvoke(IASyncResult). I'm using XP Operating System + Whidbey version 8.0.40301.9. Is it taking any other type or number of parameters ? Please guide me.
Sameeksha
Reply to this message...
System.AsyncCallback
System.IAsyncResult
System.Object
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