I have an app that runs a function that could take a decent amount of time, so I need to add a callback method. How would I go about this?
Mainly, my question is what is the type that needs to be passed to the class constructor?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
On C# (not only on WP7) you can call any function asynchronously by wrapping it in a delegate. On the delegate’s BeginInvoke call you’d pass a callback which will be invoked when the operation is completed. See the example below:
If you need to pass some additional parameter in the asyncState / userState property, you can also use the AsyncDelegate property of the IAsyncResult parameter (which for delegate calls is always System.Runtime.Remoting.Messaging.AsyncResult) and retrieve the delegate from there as well, as shown below.