在线程进行N个异步IO操作,我想在异步操作后,获取的它结果,并且将结果DataGridView控件中,有什么好方法? 如果用回调方法? 要注意些什么???

解决方案 »

  1.   

    现在的.NEt版本是不允许跨线程访问的,LZ可以查一下“多线程、控件”,一般都会有介绍:
    if(IsInvoked)
    {...}
    采用异步机制实现。
      

  2.   

    谢谢大家的回复,我用的IO异步,即所有的操作都在ThreadPool中执行。我用的回调方法,在操作dataGridveiw时
    Invodke()方法lock(dataGridView) 
    {
      //业务   
    }
      

  3.   

    2种做法,
    1.开线程做操作,完成后,更新到ui都是线程的活
    new Thread((ThreadStart)delegate
    {
        //处理准备数据
        this.Invoke((EventHandler)delegate
            {
                //更新到DataGridView
            });
    }).Start();
    2.开线程操作,操作完成后通知ui,然后ui统一更新
    Thread t1 = new Thread((ThreadStart)delegate{/*处理准备数据*/});
    Thread t2 = new Thread((ThreadStart)delegate{/*处理准备数据*/});
    Thread tn = new Thread((ThreadStart)delegate{/*处理准备数据*/});
    t1.Start();
    t2.Start();
    tn.Start();
    t1.Join();
    t2.Join();
    tn.Join();
    //更新界面