I have a function contained in a dll file that was written in vb.net. I can invoke methods in this dll ex. mydll.write(data). The problem I am having is that this dll also raises an event but I can't seem to figure out how to get this event trigged in c#.
To add to what cander said. What is the criteria for this event being fired? There should be some type of test to fire the event base on the results. Then when you subscribe to that event, it should fire based on the criteria.
Actually the event is fired, in this case when data comes in on port 514. The class is one that I use is vb to listen for UDP data comming in.
In this example I set it to listen on port 514 with the "network.listen(514)" and send data to the localhost, from its self with the statement "network.send("127.0.0.1",514,Console.Readline());" just say that i used nsender instead of network (but is correct in my tyring-to-work example) but I think my problem is this.
I am trying to make a console application (am sending data to its self just so I can figure out this "event" thing in c#) and when I try to use "this" i won't let me.
Here is some of the class, I removed some of it for simplicity sake, but this is the part where the events are raised, I just took out the stuff the seperates the data recieved and stuff like that.
This is from a thread
VB Code:
Class UDPListener 'The UDPListener Thread
Public Port As Integer 'Port to listen on
Public Enabled As Boolean = False
Public TEnable As Boolean = False
Public Event RecieveFailed(ByVal Message As String)
Public Event DataArrival(ByVal Data As String)
Public Sub Listen()
recieve the data
RaiseEvent DataArrival(datastring)
End Sub
End Class
This is from the part that sets up the thread
VB Code:
Public Class UDP 'The UDP class that listens and sends data
Public Event Paused() 'Invokes a event when the listener has been paused
Public Event Restarted() 'Invokes a event when the listener has been restarted
Public Event Distroyed() 'Invokes a event when the listener has been perminently disabled
Public Event DataSent(ByVal Data As String) 'Invokes a event when the data has been sent
Public Event DataArrival(ByVal Data As String) 'Invokes a event when data has been recieved
Public Event SendFailed(ByVal Message As String) 'Invokes a event when data could not be send to remote host
Public Event RecieveFailed(ByVal Message As String) 'Invokes a event when an error occured during data retrival
Public Event ErrorEvent(ByVal Message As String) 'Invokes a event when a subroutine encouters and error
Dim ListenerDistroyed As Boolean = False
Private WithEvents Listener As New UDPListener
Private Listenerthread As New System.Threading.Thread(AddressOf Listener.Listen)
Public Sub Listen(ByVal Port As Integer)
'Set up the listener thread
End Sub
Public Sub Pause()
'Pause the listener thread
End Sub
Public Sub Restart()
'Restart the listener thread
End Sub
Public Sub Distroy()
'Kill the listener thread
End Sub
Public Sub Send(ByVal Host As String, ByVal Port As Integer, ByVal Data As String)
'Send the data to the remote host
End Sub
Private Sub DataArived(ByVal Data As String) Handles Listener.DataArrival
RaiseEvent DataArrival(Data)
End Sub
Private Sub DataArrivalError(ByVal Message As String) Handles Listener.RecieveFailed
By the way, port 514 is the one used for logging, basically I am recreating a small logging server that is used to write data to a sql server (rather than the standard text file) from a firewall.