本帖最后由 ydlcom 于 2010-10-18 13:41:26 编辑

解决方案 »

  1.   


            private void button1_Click(object sender, EventArgs e)
            {
                Thread thr = new Thread(new ParameterizedThreadStart(TestRun));
                thr.IsBackground = true;
                object o = 1;
                //object o = new object[] { "a", 1 };//多参
                thr.Start(o);
            }
            private void TestRun(object o)
            {
                int i = (int)o;
                //object[] os = (object[])o;
                //string str = os[0].ToString();
                //int i = (int)os[1];
            }
      

  2.   

            private void fun(object index)
            {
                while (true)
                {
                    string txt = System.DateTime.Now.ToString() + "    执行第 " + index.ToString() + " 个线程";
                    if (listBox1.InvokeRequired)
                    {
                        MyDelegateUI d = delegate
                        {
                            listBox1.Items.Insert(0, txt);
                        };
                        listBox1.Invoke(d);
                    }
                    else
                    {
                        listBox1.Items.Insert(0, txt);
                    }                System.Threading.Thread.Sleep(100);
                }
            }        private void button1_Click(object sender, EventArgs e)
            {
                Thread[] t = new Thread[10];
                for (int i = 0; i < 10; i++)
                {
                    t[i] = new Thread(new ParameterizedThreadStart(fun));
                    t[i].Start(i);
                }
            }
      

  3.   


    这个看得懂,但你看一下,我这个怎么弄呢 #region [方法]【得到表格数据】
    public void getData(out DataTable dt, out SqlDataAdapter da, out SqlCommandBuilder sb, out BindingSource bs, ToolStripStatusLabel st1,  string sqlcmd,  BindingNavigator bindNager)
            {   SqlConnection conn = null;
                string connect =Maticsoft.DBUtility.DbHelperSQL.connectionString;
                da = null;
                da = null;
                sb = null;
                bs = null;
                try
                {
                    conn = new SqlConnection(connect);
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }                dt = new DataTable();
                    da = new SqlDataAdapter(sqlcmd, conn);
                    sb = new SqlCommandBuilder(da);
                    da.Fill(dt);
                    Grid.DataSource = bs;
                    bs = new BindingSource();
                    bs.DataSource = dt; 
                   grid.DataSource = bs;//这里要操作控件
                }
                catch (Exception ex )
                {
                    MessageBox.Show(ex.ToString ());
                 }
                finally
                {
                      conn.Close();
                }
            }
            #endregion
      

  4.   

    grid.DataSource = bs;//这里要操作控件
    ==>            this.Invoke(new MethodInvoker(delegate
                {
    grid.DataSource = bs;//这里要操作控件            }));