delegates:用委托来表示回调(Express Callbacks with Delegates)

Me: "Son, go mow the yard. I'm going to read for a while."

Me:“儿子,取把院子里面的草割了。我看会儿书。”

Scott: "Dad, I cleaned up the yard."

Scott: “爸爸,我已经清理完了院子。”

Scott: "Dad, I put gas in the mower."

Scott: “爸爸,我给割草机加油”

Scott: "Dad, the mower won't start."

Scott: “爸爸,割草机不工作了。”

Me: "I'll start it."

Me:“我来弄。”

Scott: "Dad, I'm done."

Scott: “爸爸,我搞定了”



This little exchange illustrates callbacks. I gave my son a task, and he (repeatedly) interrupted me with the status. I did not block my own progress while I waited for him to finish each part of the task. He was able to interrupt me periodically when he had an important (or even unimportant) status to report or needed my assistance. Callbacks are used to provide feedback from a server to a client asynchronously. They might involve multithreading, or they might simply provide an entry point for synchronous updates. Callbacks are expressed using delegates in the C# language.

这个小小的交流举例说明了回调。我给我儿子一个任务,他(重复的)打断我,告诉我他的状态。在等待他完成工作的每一步时,我没有阻塞自己的进度。当他有重要的(甚至不重要的)状态要报告,或者需要我帮助的时候,可以周期性的打断我。回调可以用来从服务器向客户异步的提供反馈。它们可能涉及到多线程,或者简单的为同步更新提供一个切入点。在C#语言里面,回调通过委托来表述。

Delegates provide type-safe callback definitions. Although the most common use of delegates is events, that should not be the _disibledevent= bContinue)

return;

}

}



In this case, I've defined the semantics so that each delegate must be true for the iteration to continue.

在这情况下,我已经定义了这个语法,那样,迭代要继续下去的话,每个委托都必须为true。

Delegates provide the best way to utilize callbacks at runtime, with simpler requirements on client classes. You can configure delegate targets at runtime. You can support multiple client targets. Client callbacks should be implemented using delegates in .NET.

委托为在运行时利用回调提供了最好的方法,在客户类上只需要简单的要求。可以在运行时配置委托目标。可以支持多播委托。在.Net里面客户回调应该使用委托来实现。

Tags:  listeningexpress express outlookexpress delegates

延伸阅读

最新评论

发表评论