我最近read this thread on MSDN .所以我在考虑使用 lambda 表达式作为调用 EndInvoke 的方式,以确保一切都很好和整洁。
哪个更正确?
示例 1:
Action<int> method = DoSomething;
method.BeginInvoke(5, (a)=>{method.EndInvoke(a);}, null);
示例 2:
Action<int> method = DoSomething;
method.BeginInvoke(5, (a)=>
{
Action<int> m = a.AsyncState as Action<int>;
m.EndInvoke(a);
}, method);
最佳答案
您的第二个示例稍微高效一些,因为“方法”委托(delegate)实例不必在闭包中捕获。我怀疑你会注意到。
关于c# - 结束 BeginInvoke 的正确方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/435772/