Dart.Snmp Namespace > SnmpSocket Class : GetResponseTaskAsync Method |
Public Function GetResponseTaskAsync( _ ByVal request As RequestMessage, _ ByVal target As IPEndPoint, _ ByVal timeout As Integer, _ ByVal retries As Integer _ ) As Task(Of ResponseMessage)
Dim instance As SnmpSocket Dim request As RequestMessage Dim target As IPEndPoint Dim timeout As Integer Dim retries As Integer Dim value As Task(Of ResponseMessage) value = instance.GetResponseTaskAsync(request, target, timeout, retries)
public Task<ResponseMessage> GetResponseTaskAsync( RequestMessage request, IPEndPoint target, int timeout, int retries )
public: Task<ResponseMessage*>* GetResponseTaskAsync( RequestMessage* request, IPEndPoint* target, int timeout, int retries )
public: Task<ResponseMessage^>^ GetResponseTaskAsync( RequestMessage^ request, IPEndPoint^ target, int timeout, int retries )
If your application uses SnmpSocket.GetResponse() on parallel threads, consider using this method instead to execute those requests asynchronously. This technique avoids the overhead of multiple worker threads. A SocketException is thrown if a timeout condition causes the socket to be closed.
This method causes a byte array to be pinned while waiting for a response. If a response is not received, this byte array will be pinned until the timeout period expires. If an infinite timeout is specified, its receiving byte array will remain pinned. This method can be cancelled by closing the underlying Socket.
private async void button1_Click(object sender, EventArgs e) { //Create Get Request GetMessage request = new GetMessage(); request.Variables.Add(manager1.Mib.CreateVariable(NodeName.sysContact)); //Create socket for sending request from. Binds to IPAddress.Any, port 0. SnmpSocket managerSocket = new SnmpSocket(manager1); //Send request and receive response ResponseMessage response = await managerSocket.GetResponseTaskAsync(request, myAgentAddress, 3000, 3); //Display info about the first variable in the response, and its value Variable vari = response.Variables[0]; label1.Text += vari.Definition.ToString() + vari.Value.ToString() + Environment.NewLine; }
Private Async Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) 'Create Get Request Dim request As New GetMessage() request.Variables.Add(manager1.Mib.CreateVariable(NodeName.sysContact)) 'Create socket for sending request from. Binds to IPAddress.Any, port 0. Dim managerSocket As New SnmpSocket(manager1) 'Send request and receive response Dim response As ResponseMessage = Await managerSocket.GetResponseTaskAsync(request, myAgentAddress, 3000, 3) 'Display info about the first variable in the response, and its value Dim vari As Variable = response.Variables(0) label1.Text &= vari.Definition.ToString() & vari.Value.ToString() & Environment.NewLine End Sub