class Program
    {
      private static int newTask(int ms)
        {
            Console.WriteLine("任务开始");
            Thread.Sleep(ms);
            Random random = new Random();
            int n = random.Next(10000);
            Console.WriteLine("任务完成");          
            return n;           
        }      
      private delegate int NewTaskDelegate(int ms);   
      static void Main(string[] args)    
        {          
          NewTaskDelegate task = newTask;         
          IAsyncResult asyncResult = task.BeginInvoke(2000, null, null);  
          int result = task.EndInvoke(asyncResult);    // EndInvoke方法将被阻塞2秒
          Console.WriteLine(result);      
        }  
    }请问,task.BeginInvoke,是怎么来的?委托中,没有这个方法啊?
查了下MSDN,BeginInvoke的返回值类型是DispatcherOperation这个东西啊,不是IAsyncResult接口啊
请解释一下异步?能否给一个异步编程的基础链接,百度么有

解决方案 »

  1.   

    delegate 的 BeginInvoke NewTaskDelegate task = newTask;private delegate int NewTaskDelegate(int ms);   
      
    http://msdn.microsoft.com/zh-cn/library/0b1bf3y3.aspx
      

  2.   

    Control.BeginInvoke  

    delegate.BeginInvoke  
    不是一个概念。可能楼上链接贴错了。
      

  3.   

    http://msdn.microsoft.com/zh-cn/library/2e08f6yc.aspx话说 delegate 应该说是一个语法糖,delegate并翻译成一个类并有四个方法: .ctor, Invoke, BeginInvoke, EndInvoke。这个类继承于 MulticastDelegate 
      

  4.   

    http://blog.csdn.net/lanruoshui/article/details/5466749http://msdn.microsoft.com/zh-cn/library/h80ttd5f.aspx
      

  5.   

    http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx
      

  6.   

    DispatcherOperation这个你大概是看到WPF中的 UI Element的BeginInvoke了
      

  7.   

    你给这个链接是Control.BeginInvoke 方法啊,
    我这好像不是控件的吧
      

  8.   

    不过,我还是没在MSDN找到Delegate.BeginInvoke
      

  9.   

    delegate.BeginInvoke 并不是父类的方法。它是CLR编译后生成的。