有人熟悉微软机器人工作室吗请解释为什么处理程序操作是虚拟的,有些是非虚拟的?
[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public virtual IEnumerator<ITask> GetHandler(Get get)
{
get.ResponsePort.Post(_state);
yield break;
}
VS
[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public IEnumerator<ITask> SubscribeHandler(Subscribe subscribe)
{
SubscribeRequestType request = subscribe.Body;
LogInfo("Subscribe request from: " + request.Subscriber);
// Use the Subscription Manager to handle the subscribers
yield return Arbiter.Choice(
SubscribeHelper(_submgrPort, request, subscribe.ResponsePort),
delegate(SuccessResult success)
{
// Send a notification on successful subscription so that the
// subscriber can initialize its own state
base.SendNotificationToTarget<Replace>(request.Subscriber, _submgrPort, _state);
},
delegate(Exception e)
{
LogError(null, "Subscribe failed", e);
}
);
yield break;
}
提前致谢。
答案 0 :(得分:0)
虚拟处理程序用在您希望用作其他类的基础的类中。非虚拟处理程序要么在派生类中声明为覆盖,要么在未派生的类中声明(在示例代码中通常就是这种情况)。
请参阅以下文章:
http://msdn.microsoft.com/en-us/library/9fkccyh4(v=VS.100).aspx