Visual Basic (Declaration) | |
---|---|
Public Overloads Sub Start( _ ByVal worker As ManagerMessageReceived, _ ByVal state As Object _ ) |
Visual Basic (Usage) | ![]() |
---|---|
Dim instance As Manager Dim worker As ManagerMessageReceived Dim state As Object instance.Start(worker, state) |
C# | |
---|---|
public void Start( ManagerMessageReceived worker, object state ) |
Managed Extensions for C++ | |
---|---|
public: void Start( ManagerMessageReceived* worker, Object* state ) |
C++/CLI | |
---|---|
public: void Start( ManagerMessageReceived^ worker, Object^ state ) |
Parameters
- worker
- ManagerMessageReceived delegate specifying the method to execute.
- state
- Information to pass to the worker delegate method; can be null.
The following example demonstrates receiving trap, notification and inform messages.
C# | ![]() |
---|---|
private void button1_Click(object sender, EventArgs e) { //Start listening for traps, notifications and informs manager1.Start(manager1_MessageReceived, null); } private void manager1_MessageReceived(Manager manager, MessageBase message, object state) { //Marshal message to the UI thread using the Message event if (message is TrapMessage) manager.Marshal(new MessageBase[] { message }, "trap"); else if (message is NotificationMessage) manager.Marshal(new MessageBase[] { message }, "notification"); else if (message is InformMessage) { manager.Marshal(new MessageBase[] { message }, "inform"); //Send response to inform message origin manager.Send(new ResponseMessage(message as InformMessage), message.Origin); } } private void manager1_Message(object sender, MessageEventArgs e) { //Update interface according to message type received switch (e.UserState.ToString()) { case "trap": TrapMessage trap = e.Messages[0] as TrapMessage; label1.Text = "Trap received with Enterprise(" + trap.Enterprise + "), Generic Type (" + trap.GenericTrap.ToString() + "), Specific Type(" + trap.SpecificTrap.ToString() + ")"; break; case "notification": NotificationMessage notification = e.Messages[0] as NotificationMessage; label1.Text = "Notification received with OID (" + notification.Oid + ")"; break; case "inform": InformMessage inform = e.Messages[0] as InformMessage; label1.Text = "Inform received with " + inform.Variables.Count.ToString() + " variable(s)."; break; } } |
Visual Basic | ![]() |
---|---|
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click 'Start listening for traps, notifications and informs manager1.Start(AddressOf manager1_MessageReceived, Nothing) End Sub Private Sub manager1_MessageReceived(ByVal manager As Manager, ByVal message As MessageBase, ByVal state As Object) 'Marshal message to the UI thread using the Message event If TypeOf message Is TrapMessage Then manager.Marshal(New MessageBase() {message}, "trap") ElseIf TypeOf message Is NotificationMessage Then manager.Marshal(New MessageBase() {message}, "notification") ElseIf TypeOf message Is InformMessage Then manager.Marshal(New MessageBase() {message}, "inform") 'Send response to inform message origin manager.Send(New ResponseMessage(TryCast(message, InformMessage)), message.Origin) End If End Sub Private Sub manager1_Message(ByVal sender As Object, ByVal e As MessageEventArgs) Handles manager1.Message 'Update interface according to message type received Select Case e.UserState.ToString() Case "trap" Dim trap As TrapMessage = TryCast(e.Messages(0), TrapMessage) label1.Text = "Trap received with Enterprise(" & trap.Enterprise & "), Generic Type (" & _ trap.GenericTrap.ToString() & "), Specific Type(" & trap.SpecificTrap.ToString() & ")" Case "notification" Dim notification As NotificationMessage = TryCast(e.Messages(0), NotificationMessage) label1.Text = "Notification received with OID (" & notification.Oid & ")" Case "inform" Dim inform As InformMessage = TryCast(e.Messages(0), InformMessage) label1.Text = "Inform received with " & inform.Variables.Count.ToString() & " variable(s)." End Select End Sub |
This method presents all asynchronous messages that may be received by a Manager (typically listening on well-known port 162). The Dart.Common.SocketBase.Socket property references the socket in use.
Unhandled exceptions occurring on the worker thread will be caught and reported by the ComponentBase.Error event.
Target Platforms: Microsoft .NET Framework 2.0