当委托完成处理时,我正在订阅DispatcherOperation的Completed事件。任何人都可以告诉我如何在Completed事件处理程序中获取委托返回的值。我认为只有通过接受Completed事件处理程序中的返回值才能阻止主线程。
DispatcherOperation dispOp = this.Dispatcher.BeginInvoke(balUpdater,
GlobalParams._sessionObject.UserInfo.CardData);
dispOp.Completed += new EventHandler(dispOp_Completed);
void dispOp_Completed(object sender, EventArgs e)
{
// accept return value of balUpdater here.
}
答案 0 :(得分:0)
我猜 sender
参数很可能是DispatcherOperation
,但如果没有,你可以捕获委托中的DispatcherOperation
:
DispatcherOperation dispOp = this.Dispatcher.BeginInvoke(balUpdater,
GlobalParams._sessionObject.UserInfo.CardData);
dispOp.Completed += (sender, args) => HandleCompletion(dispOp);
...
private void HandleCompletion(DispatcherOperation operation)
{
object result = operation.Result;
// Use the result here
}