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?
+1
A:
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);
}
Robert Harvey
2010-08-06 00:31:11
oh jeez. thanks for catching that. I didn't realize that the delegate was defined in a different section earlier in the article! How embarrassing. :)
Dave
2010-08-06 01:27:57