我得到了这个程序,它给出了语法错误“System.Threading.Tasks.task 不包含 Run 的定义。”
我正在使用 VB 2010 .NET 4.0 有什么想法吗?在 .net 4.0 中运行的任何替代品?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ChatApp
{
class ChatProg
{
static void Main(string[] args)
{
Task<int> wakeUp = DoWorkAsync(2000,"Waking up");
Task.WaitAll(wakeUp);
}
static Task<int> DoWorkAsync(int milliseconds, string name)
{
//error appears below on word Run
return Task.Run(() =>
{
Console.WriteLine("* starting {0} work", name);
Thread.Sleep(milliseconds);
Console.WriteLine("* {0} work one", name);
return 1;
});
}
}
}