Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22307

How to remove wrapped/custom event handler added from an instance of a class VB.NET

$
0
0

I need to create multiple instance of zkemkeeper.CZKEM to create active (250+) connections to multiple biometrics devices with events at a time. I created a class to do my desired output:

Public Class ZKEMEventsClass    Public CZKEM2 As New zkemkeeper.CZKEM    Public MyNewWrapperClass As MyWrapperClass    Public Sub AddBioHandler(iDevice As String, iIP As String, iPort As Integer)        If CZKEM2.Connect_Net(iIP, iPort) Then            If CZKEM2.RegEvent(1, 65535) = True Then                MyNewWrapperClass = New MyWrapperClass(iDevice, CZKEM2)                AddHandler MyNewWrapperClass.AttEventWrapper, AddressOf LogRaised                MsgBox("Handler successfully registered")            Else                MsgBox("Error Registering Events")            End If        Else            MsgBox("Error Connecting to Device")        End If    End Sub    Public Sub RemoveBioHandler(iDevice As String, CZKEM As zkemkeeper.CZKEM)>>> MyNewWrapperClass = New MyWrapperClass(iDevice, CZKEM)>>> RemoveHandler MyNewWrapperClass.AttEventWrapper, AddressOf LogRaised    End Sub    Public Sub LogRaised(ByVal SenderName As String, ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer, ByVal iHour As Integer, ByVal iMinute As Integer, ByVal iSecond As Integer, ByVal iWorkCode As Integer)        MsgBox("Raised event details here... [EnrollID, Year, Month, Day]...")    End SubEnd Class

NOTE: I created and used MyWrapperClass to embed custom device name into each biometrics device so I can identify which device [like CZKEM2] raised whatever event [like CZKEM2.OnAttTransactionEx]

Public Class MyWrapperClass    Public Property Name    Private WithEvents CZKEM As zkemkeeper.CZKEM    Public Event AttEventWrapper(SenderName As String, sEnrollNumber As String, iIsInValid As Integer, iAttState As Integer, iVerifyMethod As Integer, iYear As Integer, iMonth As Integer, iDay As Integer, iHour As Integer, iMinute As Integer, iSecond As Integer, iWorkcode As Integer)    Public Sub New(WrapperName As String, CZKEMObject As zkemkeeper.CZKEM)        Me.Name = WrapperName        Me.CZKEM = CZKEMObject    End Sub    Private Sub HandleEvent(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer, ByVal iHour As Integer, ByVal iMinute As Integer, ByVal iSecond As Integer, ByVal iWorkCode As Integer) Handles CZKEM.OnAttTransactionEx        RaiseEvent AttEventWrapper(Me.Name, sEnrollNumber, iIsInValid, iAttState, iVerifyMethod, iYear, iMonth, iDay, iHour, iMinute, iSecond, iWorkCode)    End SubEnd Class

In my main program, I used codes below:

Sub ConnectToDevice()        Dim iIP As String        Dim iDevice As String        Dim iPort As Integer        For x = 1 To 2            Select Case x                Case 1                    iIP = "122.3.47.43"                    iDevice = "Device 1"                Case 2                    iIP = "192.168.10.201"                    iDevice = "Device 2"            End Select'This is the section where I create new instance of my ZKEMEventsClass            Dim NewConnect As New ZKEMEventsClass            NewConnect.AddBioHandler(iDevice, iIP, iPort)        NextEnd Sub    Sub Disconnect()>>> For Each CZKEMObject As KeyValuePair(Of String, zkemkeeper.CZKEM) In MyWrapperClass.ListOfDevices>>> Dim NewRemoveHandler As New ZKEMEventsClass>>> NewRemoveHandler.RemoveBioHandler(CZKEMObject.Key, CZKEMObject.Value)>>> Next    End Sub

QUESTION #1:How can I remove each of my event handler or rather all when it was all created from another instance of my ZKEMEventsClass class?

QUESTION #2If question #1 is not answerable, are there other [working] options for me to meet my requirements?

I'm kind of stucked here for a week now, and I can't find anything from google similar to my problem.

Please help me anyone :(


Viewing all articles
Browse latest Browse all 22307

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>