我得到了这个程序,该程序给我语法错误“ System.Threading.Tasks.task不包含运行的定义”。
我正在使用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;
});
}
}
}