Post

BigDipper Light: Updated Async Support

This post is about the updated async support in #SNMP.

Starting from our latest change set, you need to provide one more argument to BeginGetResponse. That was the missing piece, state object.

As state object is a requirement of Microsoft .NET asynchronous pattern, now I can announce that #SNMP fully supports it. :)

Below is the updated sample code, which simply passes null as state object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using System.Net;
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;

namespace TestAsyncGet
{
    class Program
    {
        static void Main(string[] args)
        {
            GetRequestMessage message = new GetRequestMessage(0,
                VersionCode.V1,
                new OctetString("public"),
                new List<Variable> {new Variable(new ObjectIdentifier("1.3.6.1.1.1.0"))});
            var endpoint = new IPEndPoint(IPAddress.Loopback, 161);
                message.BeginGetResponse(endpoint, new UserRegistry(),endpoint.GetSocket(),
                ar => {
                    var response = message.EndGetResponse(ar);
                    Console.WriteLine(response);
                }, null);
            Console.Read();
        }
    }
}
© Lex Li. All rights reserved. The code included is licensed under CC BY 4.0 unless otherwise noted.
Advertisement

© - Lex Li. All rights reserved.

Using the Chirpy theme for Jekyll.

Last updated on November 06, 2024