小编har*_*men的帖子

在任务并行库中:如何推迟Task.TaskFactory.FromAsync任务执行?

我有一个返回任务的方法,如:

public static Task<int> SendAsync(this Socket socket, byte[] buffer, int offset, int count)
{
    if (socket == null) throw new ArgumentNullException("socket");
    if (buffer == null) throw new ArgumentNullException("buffer");

    return Task.Factory.FromAsync<int>(
        socket.BeginSend(buffer, offset, count, SocketFlags.None, null, socket),
        socket.EndSend);
}
Run Code Online (Sandbox Code Playgroud)

我想保留对该任务的引用并稍后运行它.但是,似乎由FromAsync方法创建的任务立即执行.我怎样才能推迟执行?

.net task-parallel-library

4
推荐指数
1
解决办法
3002
查看次数

标签 统计

.net ×1

task-parallel-library ×1