Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#相当于java.util.concurrent.Future<;T>;_C#_Java_Equivalent - Fatal编程技术网

c#相当于java.util.concurrent.Future<;T>;

c#相当于java.util.concurrent.Future<;T>;,c#,java,equivalent,C#,Java,Equivalent,在C#中,与Java的未来最接近的等价物是什么 例如,在C#中最接近于以下内容的重建是什么: 公共类FutureMethodCall实现Future{ 私人电话; 公共布尔值取消(布尔值可能中断刷新){ 返回此.methodCall.cancel(可能中断frunning); } 公共APIResponse get()引发ExecutionException、InterruptedException{ 返回此.methodCall.get(); } ... } 提前谢谢 我不确定将来Java会

在C#中,与Java的未来最接近的等价物是什么

例如,在C#中最接近于以下内容的重建是什么:

公共类FutureMethodCall实现Future{
私人电话;
公共布尔值取消(布尔值可能中断刷新){
返回此.methodCall.cancel(可能中断frunning);
}
公共APIResponse get()引发ExecutionException、InterruptedException{
返回此.methodCall.get();
}
...
}

提前谢谢

我不确定将来Java会做什么,但从代码来看,您似乎是在稍后执行异步运行且可取消的代码

看看在C#中,它们提供了相同的功能。

如果您不能使用Task(因为您被困在旧版本的C#中),可以在google上搜索Task,试试我的承诺实现:。也可在nuget上获得:
public class FutureMethodCall implements Future {
    private Future<APIResponse> methodCall;

    public boolean cancel(boolean mayInterruptIfRunning) {
        return this.methodCall.cancel(mayInterruptIfRunning);
    }

    public APIResponse get() throws ExecutionException, InterruptedException {
        return this.methodCall.get();
    }

    ...
}