This is the first time I've used a thread that requires returning values to another class via a callback method. I've read up on it, and it seems that everyone is using the AsyncMethodCaller. However, even though I've added the necessary reference to my project, VS 2008 thinks it's undefined... what else could I possibly be doing wrong here?
I don't see AsyncMethodCaller in the MSDN documentation, other than as part of some example code here (you define the AsyncMethodCaller delegate yourself):
http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx
Partial code follows (see the link for the entire example):
using System;
using System.Threading;
namespace Examples.AdvancedProgramming.AsynchronousOperations
{
public class AsyncDemo
{
// The method to be executed asynchronously.
public string TestMethod(int callDuration, out int threadId)
{
Console.WriteLine("Test method begins.");
Thread.Sleep(callDuration);
threadId = Thread.CurrentThread.ManagedThreadId;
return String.Format("My call time was {0}.", callDuration.ToString());
}
}
// The delegate must have the same signature as the method
// it will call asynchronously.
public delegate string AsyncMethodCaller(int callDuration, out int threadId);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With