grdData是DataGrid控件  是这个类基类的一个控件在执行回调函数 base.grdData.DataSource = dsResult 的时候报错:
    Control Created on one thread cannot be parented to a control on a different thread线程不是太懂,请有经验的人士,谈谈你们的处理方式,或者建议啊!!!!public  DataSet Query()
{
    GetRemoter(TheseParms,outParms);//调用异步方法
}
public DataSet GetRemoter(object []a,object[]b)
{
  Remoter remot = Remoter.GetInstance();
  MyDele = new deleMethod(remot.RemotingInvoke);
  AsyncCallback ac = new AsyncCallback(CallBack);
  IAsyncResult Iar = MyDele.BeginInvoke(a,out b,ac,null);
}
public  void CallBack(IAsyncResult Iar)
{

  if(Iar.IsCompleted  )
  {
    MyDele.EndInvoke(out result,Iar);
    DataSet dsResult=(DataSet)result[6];
    base.grdData.DataSource=dsResult;     // 这里有问题!!!!!!!!!!!!!!
  }
}

解决方案 »

  1.   

    不能直接操作,需要用Invoke来实现
    参看
    http://blog.csdn.net/Knight94/archive/2006/08/24/1111267.aspx
      

  2.   

    另:MSDN的解释
    访问 Windows 窗体控件本质上不是线程安全的。如果有两个或多个线程操作某一控件的状态,则可能会迫使该控件进入一种不一致的状态。还可能出现其他与线程相关的 bug,包括争用情况和死锁。确保以线程安全方式访问控件非常重要。.NET Framework 有助于在以非线程安全方式访问控件时检测到这一问题。在调试器中运行应用程序时,如果创建某控件的线程之外的其他线程试图调用该控件,则调试器会引发一个 InvalidOperationException,并提示消息:“从不是创建控件 control name 的线程访问它。” 
    所以2.0中要求使用invoke方法...
      

  3.   

    msdn 上面 2005的对Invoke 实现的 写法 ,自己看吧Write and compile your own application.On the View menu, click Class View.Expand the Class View window to find the class that you would like to test, right-click the class that requires testing, and click Create Instance.The Create Instance dialog box appears and prompts you to choose an instance name for the test.In the Name, type MyTestForThisClass.The Object Test Bench window opens and shows a rounded rectangle that represents the class. The instance name is also displayed in the box.In the Object Test Bench window, right-click your class, and click InvokeMethod.All public methods are displayed for testing.From the list on the shortcut menu, select the method or function that you want to verify, and click OK.The Invoke Method Dialog Box appears.In the Invoke Method dialog box, fill in the arguments in the Parameters text box or specify null. If any of the parameters are invalid, an exclamation point (!) is displayed next to the parameter. For example, if the argument requires an int and you type some text, the exclamation point prompts you to correct the input argument. To correct the parameter, simply retype the correct data type.Note  
    To fire an event on a class, select the event from the list box in the Call Method dialog box.
     Click OK to call the method and begin testing.If the method call succeeds, the Method Call Result Message Box is displayed with the return values from the call. If the method was void, the Method Call Result message box indicates this information explicitly. To call a static method on a type
    In Class View, right-click the name of the class whose method you want to call. -or-In the Object Test Bench window, right-click the rounded rectangle representation of the object whose method you want to call.In the Object Test Bench window, right-click your class, and click Invoke Static Method. The Invoke Static Method dialog box appears.On the list, click the static method to invoke.The Invoke Method dialog box appears.In the Invoke Method dialog box, fill in the arguments in the Parameters text box or specify null. If any of the parameters are invalid, an exclamation point (!) is displayed next to the parameter. For example, if the argument requires an int and you type some text, the exclamation point prompts you to correct the input argument. To correct the parameter, simply retype the correct data type.Click OK to call the method and begin testing.If the method call succeeds, the Method Call Result Message Box is displayed with the return values from the call. If the method was void, the Method Call Result message box indicates this information explicitly. 
      

  4.   

    1.回调函数是在异步线成执行的
    2.UI线程以外的线程操作UI不安全解决方法:判断Control的InvokeRequired属性,返回True则可以直接操作UI,返回False则需要使用control的Invoke方法。回调函数中操作DataGrid的例子
    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();
        }
      

  5.   

    参考资料http://www.codeproject.com/csharp/AsyncMethodInvocation.asp