none
线程问题 RRS feed

  • 问题

  • 本人刚学不久,请多多指教!

    错误是:错误 1 无法将类型“System.Threading.ThreadStart”隐式转换为“System.Threading.Thread” 

    错误 2 与“System.Threading.Thread.Thread(System.Threading.ThreadStart)”最匹配的重载方法具有一些无效参数 

    错误 3 参数“1”: 无法从“System.Threading.Thread”转换为“System.Threading.ThreadStart”

    代码:

     class EntryPoint
        {
            static void DisPlayNumbers()
            {
                Thread thisThread = Thread.CurrentThread;
                string name = thisThread.Name;
                Console.WriteLine("线程开始:" + name);
                Console.WriteLine(name + ":CurrentCulture" + thisThread.CurrentCulture);
                for (int i = 1; i <= 8 * interval; i++)
                {
                    if (i % interval == 0)
                    {
                        Console.WriteLine(name + ":计算启动" + i);
                    }
                }
            }
            static int interval;
            static void Main()
            {
                Console.WriteLine("interval结果显示在:");
                interval = int.Parse(Console.ReadLine());
                Thread thisThread = Thread.CurrentThread;
                thisThread.Name = "主线程";
                Thread workerStart = new ThreadStart(StartMethod);
                Thread workerThread =new Thread(workerStart);
                workerThread.Name = "Worker";
                workerThread.Start();
                DisPlayNumbers();
                Console.WriteLine("main thread 结束");
                Console.Read();
            }
            static void StartMethod()
            {
                DisPlayNumbers();
                Console.WriteLine("结束");
            }
        }  

    2010年3月27日 7:04

答案

全部回复