Invoke(delegateMethod)参数计数不匹配
我在做一个后参线程修改窗体内文本框内容的试验,这个试验的程序在VS2003里应该是好用的,现在我用VS2005来写,有错误。下面是我的代码:
/*监视特定文件夹新否新建文件,如果新建文件事件发生,向文本框写字符串*/
using System;
using System.IO;
namespace WindowsApplication1
{
class monitor:System.IO.FileSystemWatcher
{
// Source directory
public string sourceDirectory
{
get { return this.Path; }
set { this.Path = value; }
}
public delegate void MyDelegate(string v);
public MyDelegate MyDelegateMethon = null;
public monitor(string srcDir)
{
// Set up the path to the source directory
sourceDirectory = srcDir;
// Set up the different properties
// Monitor all files and directories
this.Filter = "";
// Listen for changes in the name of files and directories
// and changes in date/time of the last modification.
this.NotifyFilter = ((System.IO.NotifyFilters)((System.IO.NotifyFilters.FileName |
System.IO.NotifyFilters.DirectoryName | System.IO.NotifyFilters.LastWrite)));
this.IncludeSubdirectories = true;
this.EnableRaisingEvents = true;
// Set up the handlers for the FileSystemWatcher events
this.Created += new FileSystemEventHandler(fsw_onCreated);
}
private void fsw_onCreated(object sender, System.IO.FileSystemEventArgs e)
{
MyDelegateMethon("\r\n" + e.ChangeType + ", " + e.FullPath);
}
}
}
/*窗体代码*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void setValue(String v)
{
textBox1.Text += v;
}
private void Form1_Load(object sender, EventArgs e)
{
monitor my = new monitor(@"D:\a");
my.MyDelegateMethon = new monitor.MyDelegate(setValue);
textBox1.Invoke(my.MyDelegateMethon);//运行时这里出现“参数计数不匹配”。
}
}
}
请问这个问题是怎么回事?怎么解决?