C# MRDS:为什么处理程序是虚拟的?

发布于 2024-12-02 15:58:52 字数 1117 浏览 1 评论 0原文

熟悉微软机器人工作室的人可以解释一下为什么处理程序操作是虚拟的而有些设置为非虚拟的吗?

[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;
}

提前致谢。

Can somebody familiar with microsoft robotics studio please explain why the handler operations are virtual and some are set as non-virtual ?

[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;
}

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂人 2024-12-09 15:58:52

虚拟处理程序用在您希望用作其他类的基础的类中。非虚拟处理程序要么在派生类中声明为重写,要么在不会派生的类中声明为重写(示例代码中经常出现这种情况)。

请参阅以下文章:

http://msdn .microsoft.com/en-us/library/9fkccyh4(v=VS.100).aspx

什么是虚拟方法?

C# 虚拟方法问题

为什么应该在 C# 中显式重写虚拟方法?

Virtual handlers are used in classes you expect to use as base for other classes. Handlers that are not virtual are either declared as overrides in derived classes, or in classes that will not be derived (as is often the case in sample code).

Refer to the following articles:

http://msdn.microsoft.com/en-us/library/9fkccyh4(v=VS.100).aspx

What are Virtual Methods?

C# virtual methods question

WHy should virtual methods be explicitly overridden in C#?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文