dotnet ubuntu14.04错误CS0246:类型或命名空间名称'线程'无法找到

时间:2016-03-04 07:07:32

标签: .net multithreading ubuntu-14.04 coreclr

我按照" http://dotnet.github.io/getting-started/"上的说明在ubuntu.14.04-x64上安装了Dotnet。然后我写了一个简单的线程代码,

using System;
using System.Threading;

namespace mythread
{
public class threader
{
    public static void thread1()
    {
        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine("Thread1 value: {0}.", i);
        }
    }
    public static void thread2()
    {
        for (int j = 0; j < 10; ++j)
        {
            Console.WriteLine("Thread2 value: {0}.", j);
        }
    }
}

public class class1
{
    public static void Main()
    {
    ThreadStart t1 = new ThreadStart(threader.thread1);
    ThreadStart t2 = new ThreadStart(threader.thread2);
    Thread tr1 = new Thread(t1);
    Thread tr2 = new Thread(t2);
    tr1.Start();
    tr2.Start();
    }
}
}

运行此代码后,我收到了错误消息 &#34;错误CS0246:类型或命名空间名称&#39;线程&#39;找不到(你是否错过了使用指令或汇编引用?)&#34;。 有人可以帮我解决吗?

我的project.json是

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
        "NETStandard.Library": "1.0.0-rc2-23811"
    },

    "frameworks": {
        "dnxcore50": {
            "dependencies": {
      "System.Threading": "4.0.11-rc2-23811",
        "System.Threading.Tasks": "4.0.11-rc2-23811"
            }
        }
    },
     "configurations": {
    "Debug": {
      "compilationOptions": {
        "define": ["DEBUG", "TRACE"]
      }
    },
    "Release": {
      "compilationOptions": {
        "define": ["RELEASE", "TRACE"],
        "optimize": true
      }
    }
  }
}

提前致谢。

1 个答案:

答案 0 :(得分:1)

您需要System.Threading.Thread

中对project.json的引用