我正在使用一些旧代码,它们使用 IAsyncResult 模式。已经为开始和结束操作定义了委托。我应该如何将它们重构为基于任务而不用担心代表的实现?
当前代码示例:
this.CallAsync(
(thisRef, t, c, s) => thisRef.SomeMethod(thisRef.targetHost, t, c, s),
(thisRef, r) => thisRef.SomeMethod2(r));
Run Code Online (Sandbox Code Playgroud)
其中定义如下:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1336 次 |
| 最近记录: |