C#在以下方法或属性之间调用不明确

Vla*_*lad 6 c# monodevelop ambiguous

在编译我的程序时(我从MonoDevelop IDE编译它)我收到一个错误:

错误CS0121:以下方法或属性之间的调用不明确: System.Threading.Thread.Thread(System.Threading.ThreadStart)' and System.Threading.Thread.Thread(System.Threading.ParameterizedThreadStart)'(CS0121)

这里是代码的一部分.

Thread thread = new Thread(delegate {
    try
    {
        Helper.CopyFolder(from, to);
        Helper.RunProgram("chown", "-R www-data:www-data " + to);
    }
    catch (Exception exception)
    {
        Helper.DeactivateThread(Thread.CurrentThread.Name);
    }
    Helper.DeactivateThread(Thread.CurrentThread.Name);
});
thread.IsBackground = true;
thread.Priority = ThreadPriority.Lowest;
thread.Name = name;
thread.Start();
Run Code Online (Sandbox Code Playgroud)

dtb*_*dtb 8

delegate { ... }是一个匿名方法,可以分配给任何委托类型,包括ThreadStartParameterizedThreadStart.由于Thread类提供了两种参数类型的构造函数重载,因此构造函数重载的含义是不明确的.

delegate() { ... }(注意括号)是一个不带参数的匿名方法.它可以分配给委派没有参数,如类型ActionThreadStart.

所以,将代码更改为

Thread thread = new Thread(delegate() {
Run Code Online (Sandbox Code Playgroud)

如果你想使用ThreadStart构造函数重载,或者

Thread thread = new Thread(delegate(object state) {
Run Code Online (Sandbox Code Playgroud)

如果你想使用ParameterizedThreadStart构造函数重载.