电话是以下方法或属性С#之间暧昧 [英] The call is ambiguous between the following methods or properties С#

查看:277
本文介绍了电话是以下方法或属性С#之间暧昧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

While compiling my program (i compile it from MonoDevelop IDE) i receive an error:

错误CS0121:呼叫之间暧昧下面的方法或
属性:
System.Threading.Thread.Thread(System.Threading.ThreadStart)'和
的System.Threading .Thread.Thread(System.Threading.ParameterizedThreadStart)'
(CS0121)

Error CS0121: The call is ambiguous between the following methods or properties: 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();



感谢您的关注。

Thanks for your attention

推荐答案

委托{...} 是一个匿名方法可以被分配到的任何委托类型,包括的ThreadStart ParameterizedThreadStart 。由于Thread类提供构造函数重载与两个参数类型,它是暧昧而构造函数重载意思。

delegate { ... } is a an anonymous method that can be assigned to any delegate type, including ThreadStart and ParameterizedThreadStart. Since the Thread Class provides constructor overloads with both argument types, it's ambiguous which constructor overload is meant.

委托(){...} (注意括号)是一个匿名方法没有参数。它可以分配的以委派没有参数的类型,如动作的ThreadStart

delegate() { ... } (note the parenthesis) is a an anonymous method that takes no arguments. It can be assigned only to delegate types that take no arguments, such as Action or ThreadStart.

那么,更改您的代码

Thread thread = new Thread(delegate() {

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

if you want to use the ThreadStart constructor overload, or to

Thread thread = new Thread(delegate(object state) {

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

if you want to use the ParameterizedThreadStart constructor overload.

这篇关于电话是以下方法或属性С#之间暧昧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆