Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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# 将IAsyncResult模式转换为任务_C#_.net - Fatal编程技术网

C# 将IAsyncResult模式转换为任务

C# 将IAsyncResult模式转换为任务,c#,.net,C#,.net,我正在处理一些使用IAsyncResult模式的旧代码。已经为开始和结束操作定义了委托。我应该如何将这些重构为基于任务的,而不必担心代理的实现 当前代码的示例: this.CallAsync( (thisRef, t, c, s) => thisRef.SomeMethod(thisRef.targetHost, t, c, s), (thisRef, r) => thisRef.SomeMethod2(r)); 其中定义如下: void CallAsync(Beg

我正在处理一些使用IAsyncResult模式的旧代码。已经为开始和结束操作定义了委托。我应该如何将这些重构为基于任务的,而不必担心代理的实现

当前代码的示例:

this.CallAsync(
    (thisRef, t, c, s) => thisRef.SomeMethod(thisRef.targetHost, t, c, s),
    (thisRef, r) => thisRef.SomeMethod2(r));
其中定义如下:

void CallAsync(BeginCall beginCall, EndCall endCall) {
    // do some async operations with beginCall and endCall
}

delegate IAsyncResult BeginCall(T thisPtr, TimeSpan timeout, AsyncCallback callback, object state);
delegate void EndCall(T thisPtr, IAsyncResult r);

我认为最安全的办法是使用这种方法。您需要选择正确的重载以适合现有的代理定义