Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use AsyncMethodCaller?

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?

like image 629
Dave Avatar asked Aug 06 '10 00:08

Dave


1 Answers

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);
}
like image 121
Robert Harvey Avatar answered Sep 30 '22 21:09

Robert Harvey