2012-01-27 95 views
0

我试图按照从MSDN这个例子:http://msdn.microsoft.com/en-us/library/a1hetckb.aspx参数数量不匹配

我觉得我做他们所做的一切,但我不断收到此错误:参数数量不匹配

这里是我的代码:

Form1中:

namespace ETL 
{ 
    public partial class Form1 : Form 
    { 
     private Thread myThread; 
     public delegate void delegatePrintoutProcess(string myString); 
     public delegatePrintoutProcess myDelegate2; 
    ... 

    private void startParseToolStripMenuItem_Click(object sender, EventArgs e) 
    { 
     myDelegate2 = new delegatePrintoutProcess(updatePrintoutMethod); 
     myThread = new Thread(new ThreadStart(ThreadFunction)); 
     myThread.Start(); 
    } 
    public void updatePrintoutMethod(string text) 
    { 

     // this.richTextBox1.Text = text; 
    } 
    private void ThreadFunction() 
    { 
     parseFile myThreadClassObject = new parseFile(this); 
     myThreadClassObject.getFilePath = filePath; 
     myThreadClassObject.Run(); 


    } 
} 

parseFile类:

namespace ETL 
{ 
    public class parseFile 
    { 
     Form1 myFormControl1; 
    public parseFile(Form1 myForm) 
    { 
     //get a handle on the main form 
     myFormControl1 = myForm; 
    } 
    String myString; 
    public void Run() 
    { 

     for (int i = 1; i <= 5; i++) 
     { 
      myString = "Step number " + i.ToString() + " executed"; 
      Thread.Sleep(400); 
      // Execute the specified delegate on the thread that owns 
      // 'myFormControl1' control's underlying window handle with 
      // the specified list of arguments. 
      myFormControl1.Invoke(myFormControl1.myDelegate, 
            new Object[] { myString }); //error here 
     } 
    } 
    } 

我很确定我跟着提供的例子,所以不知道是怎么回事。

感谢 杰森

+0

可能是您的委托方法中缺少参数。看它。 – 2012-01-27 03:26:07

回答

2

猜想(因为没有代码证明) - 的myDelegate类型是“0或2个参数的函数”,不像myDelegate2,你可能想打电话。

+0

感谢您的回复。 “无代码证明”是什么意思? – jason 2012-01-27 03:15:42

+0

等一下,我知道你的意思。谢谢,生病看看是否它 – jason 2012-01-27 03:17:19

+0

谢谢,我完全错过了错字! – jason 2012-01-27 03:23:30