【发布时间】:2018-06-19 19:24:20
【问题描述】:
我有这个代码:
static void Main(string[] args)
{
// start import process
Task<int> task = StartImportProcess();
task.Wait();
// check result
// process finished
Console.ReadKey();
}
static async Task<int> StartImportProcess()
{
int result = 0;
result = await ImportCustomers();
// some other async/await operations
return result;
}
static Task<int> ImportCustomers()
{
// some heavy operations
Thread.Sleep(1000);
return 1; // <<< what should I return?
}
使用Task 和async/await。我想返回一个int 作为任务的结果。我应该返回哪个对象? return 1; 不起作用。
【问题讨论】:
-
return Task.FromResult(1)更多关于Task.FromResult
标签: c# async-await task