Dart.Snmp Namespace > SnmpBase Class > Start Method : Start(ThreadStart,IPEndPoint,Boolean,Object) Method |
Public Overloads Sub Start( _ ByVal worker As ThreadStart, _ ByVal localEP As IPEndPoint, _ ByVal dualMode As Boolean, _ ByVal state As Object _ )
Dim instance As SnmpBase Dim worker As ThreadStart Dim localEP As IPEndPoint Dim dualMode As Boolean Dim state As Object instance.Start(worker, localEP, dualMode, state)
public void Start( ThreadStart worker, IPEndPoint localEP, bool dualMode, object state )
public: void Start( ThreadStart* worker, IPEndPoint* localEP, bool dualMode, Object* state )
public: void Start( ThreadStart^ worker, IPEndPoint^ localEP, bool dualMode, Object^ state )
This method is used to execute functions on multiple, concurrent worker threads. Applications should use this technique to execute processes (like a series of GetRequest methods) that would block the current thread. For example, a complex application could contact several agents concurrently by running multiple requests on multiple threads.
localEP.AddressFamily must match the AddressFamily of the target SNMP entity unless dualMode is true and localEP.Address is IPAddress.IPv6Any or an IPv4-mapped IPv6 address. If dual mode (simultaneous IPv4 and IPv6) socket operation is desired, use IPAddress.IPv6Any (for all IPv4 and IPv6 interfaces) or an IPv4-mapped IPv6 address for the localEP address, and true for the dualMode argument. An IPv4-mapped IPv6 address is the IPv4 address of a network interface preceded by "::ffff:". Ex: ::ffff:192.168.1.1.
Socket resources are automatically released when the user method completes, including DTLS connection resources. Unhandled exceptions thrown on the worker thread are caught and reported by the Error event.
private void button1_Click(object sender, EventArgs e) { //Create and send request on a worker thread manager1.Start(manager1_SendGetRequest, manager1.Mib.CreateVariable(NodeName.sysContact)); } private void button2_Click(object sender, EventArgs e) { //If you don't have the MIB, retrieve the value by IID: manager1.Start(manager1_SendGetRequest, new Variable("1.3.6.1.2.1.1.4.0")); } private void manager1_SendGetRequest(SnmpSocket managerSocket, object state) { //Create Get Request GetMessage request = new GetMessage(); request.Variables.Add(state as Variable); //Send request and get response ResponseMessage response = managerSocket.GetResponse(request, myAgentAddress); //Marshal response to the UI thread using the Message event manager1.Marshal(new ResponseMessage[] { response }, "", null); } private void manager1_Message(object sender, MessageEventArgs e) { //Display info about the first variable in the response, and its value Variable vari = e.Messages[0].Variables[0]; label1.Text += vari.Definition.ToString() + vari.Value.ToString() + "\r\n"; }
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) 'Create and send request on a worker thread manager1.Start(AddressOf manager1_SendGetRequest, manager1.Mib.CreateVariable(NodeName.sysContact)) End Sub Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) 'If you don't have the MIB, retrieve the value by IID: manager1.Start(AddressOf manager1_SendGetRequest, New Variable("1.3.6.1.2.1.1.4.0")) End Sub Private Sub manager1_SendGetRequest(ByVal managerSocket As SnmpSocket, ByVal state As Object) 'Create Get Request Dim request As New GetMessage() request.Variables.Add(TryCast(state, Variable)) 'Send request and get response Dim response As ResponseMessage = managerSocket.GetResponse(request, myAgentAddress) 'Marshal response to the UI thread using the Message event manager1.Marshal(New ResponseMessage() { response }, "", Nothing) End Sub Private Sub manager1_Message(ByVal sender As Object, ByVal e As MessageEventArgs) 'Display info about the first variable in the response, and its value Dim vari As Variable = e.Messages(0).Variables(0) label1.Text &= vari.Definition.ToString() & vari.Value.ToString() & vbCrLf End Sub