【问题标题】:VB.NET Class implements eventVB.NET 类实现事件
【发布时间】:2014-04-09 03:18:34
【问题描述】:

我看不出我做错了什么。

IDE 告诉我

 "Class 'CaptureDevice' needs to implement event 'Event NewFrame(sender As Object, e As CameraEventArgs) for 'IVideoSource'.

“CaptureDevice”类如下所示:

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Net
Imports dshow
Imports dshow.Core

Namespace VideoSource

    Public Class CaptureDevice
        Implements IVideoSource
        Private source As String
        Private m_userData As Object = Nothing
        Private m_framesReceived As Integer

        Private thread As Thread = Nothing
        Private stopEvent As ManualResetEvent = Nothing

        ' new frame event '
        Public Event NewFrame As CameraEventHandler

        '(...)'
    End Class
End Namespace

我的课程“IVideoSource”如下所示:

Namespace VideoSource

    'IVideoSource interface'
    Public Interface IVideoSource

        Event NewFrame As CameraEventHandler

    End Interface

End Namespace

有谁知道我哪里出错了或可能遗漏了什么?

非常感谢您的帮助!

【问题讨论】:

  • 你的界面中是否声明了另一个带有签名Event NewFrame(sender As Object, e As CameraEventArgs)的事件?
  • CameraEventHandler 是否也在 VideoSource 命名空间内?

标签: c# vb.net events interface


【解决方案1】:

在您的 CaptureDevice 课程中,改为这样做:

Public Event NewFrame As CameraEventHandler Implements IVideoSource.NewFrame

虽然 C# 假定与已实现接口的成员具有相同名称的公共成员作为实现,但 VB.NET 要求显式声明实现。

【讨论】:

    【解决方案2】:

    您需要添加Implements 子句,因此,类似于:

    Public Event NewFrame As CameraEventHandler Implements IVideoSource.NewFrame
    

    VB.Net 没有 c# 的隐式接口实现。

    【讨论】:

    • 那行不通。 IDE 告诉我“接口中的事件可能不会被声明为‘实现’。
    • @tmighty 这不可能。您确定以完全相同的方式声明事件吗?
    • @tmighty - 听起来您正在尝试将Implements 应用于接口定义。那是错误的。您将其应用于CaptureDevice 中的Event
    猜你喜欢
    • 2015-12-10
    • 2019-03-23
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多