我正在使用一些使用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);发布于 2018-10-09 22:18:09
我认为最安全的选择是使用TaskFactory.FromAsync方法。您需要选择正确的重载以适应现有的委托定义。
https://stackoverflow.com/questions/52730012
复制相似问题