private void CallBack(IAsyncResult ar)
        {
            // get the dataset as output
            DataSet ds = m_invokeMe.EndInvoke(ar);            // update the grid a thread safe fasion!
            MethodInvoker updateGrid = delegate
            {
                m_grid.DataSource = ds.Tables[0];
            };            if (m_grid.InvokeRequired)
                m_grid.Invoke(updateGrid);
            else
                updateGrid();
        }
上面的代码是http://www.codeproject.com/csharp/AsyncMethodInvocation.asp中的一段。其中
MethodInvoker updateGrid = delegate
            {
                m_grid.DataSource = ds.Tables[0];
            };
这是什么意思?

解决方案 »

  1.   

    MethodInvoker是一个委托类型,声明为:
    public delegate void MethodInvoker();
    我认为
    MethodInvoker   updateGrid   =   delegate 
                            { 
                                    m_grid.DataSource   =   ds.Tables[0]; 
                            }; 
    的意思是创建一个MethodInvoker类型的委托对象,代码为:
    m_grid.DataSource   =   ds.Tables[0];