日期:2014-05-20  浏览次数:21114 次

求助帖,关于重载的方法与委托不匹配,如何解决???代码如下:
C# code

            #region 调用后台线程执行打印操作 begin
            Thread threadPrint = [color=#FF0000]new Thread(new ParameterizedThreadStart(PrintBarCode));[/color]
            threadPrint.IsBackground = true;
            threadPrint.Start(this.dgvPiLiang);
            //threadPrint.Join();
            #endregion 调用后台线程执行打印操作end



方法PrintBarCode的声明如下
C# code

 private void PrintBarCode(DataGridView dgvTemp)
        {
            if (dgvTemp.InvokeRequired)
            {
                PrintBarCodeDeleg printDeleg = new PrintBarCodeDeleg(PrintBarCode);
                dgvTemp.BeginInvoke(printDeleg, dgvTemp);
            }
            else
            {
              .
              .
              .
             }



请问是方法声明的不对,还是创建的线程的方法不对???

------解决方案--------------------
PrintBarCode(DataGridView dgvTemp)
改为
PrintBarCode(object dgvTemp)
{
DataGridView dgv=dgvTemp as DataGridView;
......
}

------解决方案--------------------
你看ParameterizedThreadStart委托定义参数是object类型的。
public delegate void ParameterizedThreadStart (
Object obj
)


DataGridView dgv=dgvTemp as DataGridView;不会影响数据的
------解决方案--------------------
C# code
Thread threadPrint = new Thread(new ParameterizedThreadStart(PrintBarCode));
threadPrint.IsBackground = true;
            threadPrint.Start(this.dgvPiLiang);
=>
Thread threadPrint = new Thread(_=>{PrintBarCode(this.dgvPiLiang);});
threadPrint.IsBackground = true;
threadPrint.Start();