now*_*ed. 2 .net c# task task-parallel-library
我可能错过了这里的一些东西.语法不正确.
static Task<int> MathOperation(int number)
{
//return new Task(new Func(TestMethod(number)));
}
static int LongRunningMethod(int number)
{
// some long running operation
}
Run Code Online (Sandbox Code Playgroud)
如何编写return声明MathOperation?
我收到此错误:使用泛型类型'System.Func'需要1个类型参数.
您可以使用Lambda表达式.你应该避免使用,new Task因为它返回一个"冷任务",这意味着Task必须开始使用Start().请Task.Run改用.
static Task<int> MathOperation(int number)
{
return Task.Run(() => TestMethod(number));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |